vue—之路
v-model 双向绑定
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="a">
<p>{{ message }}</p>
<input v-model="message">
</div>
<script>
new Vue({
el: '#a',
data : {
message: ''
}
})
</script>
</body>
</html>
显示效果
输入框显输入的内容
字符串反转
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="a">
<p>{{ message }}</p>
<button v-on:click="function()">按钮</button>
</div>
<script>
new Vue({
el: '#a',
data: {
message: 'runoob'
},
methods: {
function() {
this.message = this.message.split('').reverse().join('')
}
}
})
</script>
</body>
</html>
if -else
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例 - 菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
</head>
<body>
<div id="app">
<div v-if="message !=null">
Sorry
</div>
<div v-else>
Not sorry
</div>
</div>
<script>
new Vue({
el: '#app',
data:{
message:''
}
})
</script>
</body>
</html>