一、设置属性的值: {{data中的数据}}
window.onload = function () {
var c = new Vue({
el : '#box',
data : {
url : 'https://img6.bdstatic.com/img/image/smallpic/weijupaishefensetu.jpg'
}
});
}
<div id="box">
<img src="{{url}}" alt=""/>
</div>
二、v-bind绑定属性的值
window.onload = function () {
var c = new Vue({
el : '#box',
data : {
url : 'https://img6.bdstatic.com/img/image/smallpic/weijupaishefensetu.jpg'
}
});
} <div id="box">
<img v-bind:src="url" alt=""/>
</div>
三、简写方式,冒号 (:) 绑定
window.onload = function () {
var c = new Vue({
el : '#box',
data : {
url : 'https://img6.bdstatic.com/img/image/smallpic/weijupaishefensetu.jpg'
}
});
}
<div id="box">
<img :src="url" alt=""/>
</div>
四、绑定多个属性
window.onload = function () {
var c = new Vue({
el : '#box',
data : {
url : 'https://img6.bdstatic.com/img/image/smallpic/weijupaishefensetu.jpg',
w : '400px',
t : '这是一张百度图片'
}
});
} <div id="box">
<img :src="url" :width="w" :title="t" alt=""/>
</div>