The main methods option defines an execution function, the following example focuses on three ways assembly,
Including the definition and use internal components and external components and custom components
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>methods option</title>
<script src="../assets/js/vue.js"></script>
</head>
<body>
<h1>methods option</h1>
<hr>
<div id="app">
{{count}}
<p><button @click="add(2)">add</button></p>
<p>
<btn @click.native="add(2)"></btn>
</p>
</div>
<button onclick="app.add(2)">外部ADD</button>
<script>
was BTN = {
template: `<button>组件ADD</button>`
}
was app = new Vue ({
the '#app'
data: {
count: 1
},
components: {
'BTN': BTN
},
methods: {
add (num) {
if (num != '') {
this.count += num
} else {
this.count++
}
}
}
})
</script>
</body>
</html>