<html lang="en">
<head>
<meta charset="UTF-8">
<title>属性绑定和双向数据绑定</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div title="this is hello world">hello world</div>//title作用是当鼠标放在hello world 上面的时候,显示this is hello world
</div>
<script>
new Vue({
el:"#root",
})
</script>
</body>
</html>
提示语可变的情况:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>属性绑定和双向数据绑定</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div v-bind:title="title">hello world</div>//使用模板指令,等号后面跟的是一个JS表达式 v-bind:可以缩写成:
</div>
<script>
new Vue({
el:"#root",
data:{
title:"this is hello world"//此时数据项的title 和上面的属性做好了数据绑定
}
})
</script>
</body>
</html>
下面是双向绑定:
所谓单向绑定,即
<html lang="en">
<head>
<meta charset="UTF-8">
<title>属性绑定和双向数据绑定</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div :title="'dell lee'+title">hello world</div>
<input :value="content"/>//此时在input框里面输入其他的字符,content的值不会受到影响
<div>{{content}}</div>//content数据决定页面的显示,页面无法决定数据里面的内容,
</div>
<script>
new Vue({
el:"#root",
data:{
title:"this is hello world",
content:"this is content"
}
})
</script>
</body>
</html>
如何做到,当input里面的值发生改变的时候,content中的值也随之发生变化,使用指定模板v-model="content"<html lang="en">
<head>
<meta charset="UTF-8">
<title>属性绑定和双向数据绑定</title>
<script src="./vue.js"></script>
</head>
<body>
<div id="root">
<div :title="'dell lee'+title">hello world</div>
<input v-model="content"/>
<div>{{content}}</div>
</div>
<script>
new Vue({
el:"#root",
data:{
title:"this is hello world",
content:"this is content"
}
})
</script>
</body>
</html>
来源:https://www.cnblogs.com/Regina-o/p/9501019.html