event binding
- Create demo5.html with the following content
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- 1. 导入 vue 脚本文件 -->
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<!-- DOM区域 -->
<div id="app">
<h3>count value: {
{
count}}</h3>
<!-- v-on: vue事件函数 -->
<button v-on:click="addCount">+1</button>
<!-- js 事件函数 -->
<button @click="count+=1">+1</button>
</div>
</body>
<script>
const vm = {
data: function() {
return {
count: 0,
}
},
methods: {
addCount() {
this.count += 1
},
},
}
const app = Vue.createApp(vm)
app.mount('#app')
</script>
</html>
Show results