vue学习08 v-bind指令
v-bind指令的作用是为元素绑定属性
完整写法是v-bind:属性名,可简写为:属性名
练习代码为:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>v-bind</title>
</head>
<style>
.active{
border:1px solid red;
}
</style>
<body>
<!-- v-bind 为元素绑定属性 :是简写 -->
<div id="app">
<img v-bind:src="imgSrc" alt=""><br>
<img :src="imgSrc" alt="" :title="imgTitle+'!!!'"
:class="isActive? 'active':''" @click="toggleActive">
<br>
<img :src="imgSrc" alt="" :title="imgTitle+'!!!'"
:class="{active:isActive}" @click="toggleActive">
</div>
<script src="js/vue.js"></script>
<script>
var app = new Vue({
el:"#app",
data: {
imgSrc: "images/123.jpg",
imgTitle:"侠客小飞喜欢学vue!",
isActive: false
},
methods: {
toggleActive: function() {
this.isActive = !this.isActive;
}
}
})
</script>
</body>
</html>
运行效果为: