基础js代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>
<h1>0</h1>
<button>按我加一</button>
<button>按我减一</button>
</div>
<script>
var a1 = document.getElementsByTagName("h1")[0];
var b1 = document.getElementsByTagName("button")[0];
var b2 = document.getElementsByTagName("button")[1];
var num = 0
b1.onclick = function () {
num++;
a1.innerHTML=num;
}
b2.onclick=function(){
num--;
a1.innerHTML=num;
}
</script>
</body>
</html>
vue数据驱动试图
核心代码
new Vue({
//挂载点
el: '#app',
//数据
data: {
a: 0
},
//方法
methods: {
add() {
this.a++
},
minus() {
this.a--
}
},
})
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<h1>{{ a }}</h1>
<button @click="add">按我加一</button>
<button @click="minus">按我减一</button>
</div>
<script src="js/vue.js"></script>
<script>
new Vue({
//挂载点
el: '#app',
//数据
data: {
a: 0
},
//方法
methods: {
add() {
this.a++
},
minus() {
this.a--
}
},
})
</script>
</body>
</html>
标签:a1,Vue,getElementsByTagName,学习,num,var,document
From: https://www.cnblogs.com/alwaysz/p/18618919