1.数据的双向绑定
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>v-model数据双向绑定练习</title>
<!-- 通过cdn引入vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<!-- vue-app根容器 -->
<div id="app">
<input type="text" v-model="name" placeholder="请输入" />
<h2>你好,{{name}}</h2>
</div>
<script type="text/javascript">
//实例化一个vue对象
var app = new Vue({
el: '#app',
data:{
name:'不必'
}
})
</script>
</body>
</html>
运行结果
image.png
2.使用v-bind绑定data中的属性
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<!-- 通过cdn引入vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<!-- vue-app根容器 -->
<div id="app">
<p>姓名:{{name}}</p>
<input type="text" v-bind:value="descrption" />
<a v-bind:href="url">{{website}}</a>
<img :src="avatar" >
</div>
<script type="text/javascript">
//实例化一个vue对象
var app = new Vue({
el: '#app',
data:{
name:'尤雨溪',
description:'Vue.js的创立者',
website:'Vue.js官网',
url:'https://cn.vuejs.org/',
avatar:'https://gss1.bdstatic.com/9vo3dSag_xI4khGkpoWK1HF6hhy/baike/w%3D268%3Bg%3D0/sign=c08a0c60a844ad342ebf8081e8996bc9/4afbfbedab64034f29596c8ba6c379310b551da2.jpg'
}
})
</script>
</body>
</html>
运行结果
image.png
网友评论