<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>初始化helloworld</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
{{message}}
<h1>{{name}}</h1>
</div>
<script>
const app=new Vue({
el: '#app',//用于挂载要管理 的数据
data:{
//定义数据
message:"hellow",
name:"22"
}
})
</script>
</body>
</html>
v-for指令
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>遍历列表</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
{{message}}</br>
<ul>
<li v-for="item in movies">{{item}}</li>
</ul>
</div>
<script>
const app=new Vue({
el:'#app',
data:{
message: "你好啊",
movies: ['海豚湾',"海蜇","星际穿越"]
}
})
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue计数器</title>
<script src="../js/vue.js"></script>
</head>
<body>
<div id="app">
<h2>当前计数: {{counter}}</h2>
<!-- <button v-on:click="counter++">+</button>-->
<!-- <button v-on:click="counter--">-</button>-->
<button v-on:click="add">+</button>
<button @click="sub">-</button>
</div>
<script>
const app=new Vue({
el:"#app",
data:{
counter:0
},
methods:{
add: function (){
console.log("add被执行");
this.counter++;
},
sub:function (){
console.log("sub被执行");
this.counter--;
}
},
})
</script>
</body>
</html>
image.png
image.png
网友评论