<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.active{
color: red;
}
</style>
</head>
<body>
<div id="app">
<h2>{{message}} 你好世界,相对于v-text,Mustache不会覆盖</h2>
<h2 v-once>{{message}}</h2>
<h2 v-html="AHtml"></h2>
<h2 v-text="message">覆盖</h2>
<h2 v-pre>{{message}}</h2>
<ul>
<li v-for="(item,index) in movies" :class="{active:index==currentIndex}" @click="FindIndex(index)">{{index}} - {{item}}</li>
</ul>
</div>
<script src="../js/vue.js"></script>
<script>
const app=new Vue({
el: '#app',
data: {
message:'Hello world',
AHtml:'<a href="http://www.baidu.com">百度一下</a>',
movies:['海蜇王','海贼王','灌篮高手','火影忍者'],
currentIndex:0
},
methods:{
FindIndex:function(index){
this.currentIndex=index
}
}
})
</script>
</body>
</html>
针对为什么不用var而用const和let:
let定义变量、const定义常量,var基本不用了
创建Vue的基本属性:el、data、mehods,其中el指明作用的控件