<!DOCTYPE html>
<html lang="zh">
<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>Vue.js自学:利用Vue做一个计数器</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h2>当前计数值:{{count}}</h2>
<button v-on:click="add">+</button>
<button @click="sub">-</button>
</div>
</body>
<script type="text/javascript">
//v-on:click=”function”
//v-on 监听事件
//v-on:click 监听点击事件
//v-on:click=”function” 监听点击事件增加多一个函数
//methods:挂载函数方法
//$this.count:找到当前的属性
//{{message}}基础输出
const app = new Vue({
el:’#app’,
data:{
count:’1’
},
methods:{
add:function(){
this.count++;
console.log(‘增长正常执行’);
},
sub:function(){
this.count—;
console.log(‘减少正常执行’);
}
}
})
</script>
</html>