<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.red {
color: red;
}
</style>
</head>
<body>
<div id="app">
</div>
<script src="./node_modules/vue/dist/vue.js"></script>
<script>
var vm = new Vue({
el: '#app',
data: function () {
return {
msg: '指令系统',
msg2: '<h2>指令系统</h2>',
isShow: true,
text: 'hi',
isRed: true,
menu: [
{id: 1, name: 'apple', price: 10},
{id: 2, name: 'banana', price: 11},
{id: 3, name: 'watermelon', price: 30}
],
student: {
name: 'zs',
age: 17,
sex: 'boy'
}
}
},
methods: {
clickHandler(e) {
this.isRed = !this.isRed;
}
},
template: `
<div>
<h2>{{msg}}</h2>
<p v-text="msg"></p>
<p v-html="msg2"></p>
<p v-text="1+1"></p>
<p v-if="isShow">true</p>
<p v-if="isShow">false</p>
<p v-if="Math.random() > 0.5">显示</p>
<p v-else="!isShow">隐藏</p>
<p v-show="isShow">show</p>
<p v-show="!isShow">hide</p>
<p v-bind:class="{red: true}" :aa= 'text'>box</p>
<p v-bind:class="{red: isRed}" :aa= 'text'>box</p> // 数据驱动视图
<p v-on:click="clickHandler" v-bind:class="{red: isRed}">box click</p>
<ul>
<li v-for="(item, index) in menu">
<h5 v-text="item.id"></h5>
<h3>{{item.name}}</h3>
<em>{{item.price}}</em>
</li>
</ul>
<ul>
<li v-for="(value, key) in student">
{{key}} === {{value}}
</li>
</ul>
</div>
`
});
</script>
</body>
</html>