xml
复制代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>v-bind</title>
<script type="text/javascript" src="../assets/js/vue.js"></script>
</head>
<body>
<h1>v-bind</h1>
<hr>
<div id="app">
<img v-bind:src="img" alt="">
<br>
<a :href="baidu" target="_blank">点击 v-bind缩写</a>
<hr>
<div :class="one">
1.绑定class
</div>
<div :class="{one:isOk}">
2.绑定class中的判断
</div>
<div :class="[className,className1]">
3.绑定多个class
</div>
<div :class="isOk?one:two">
4.绑定class中的三元运算符
</div>
<div :style="{color:red,fontSize:mix}">
5.绑定style
</div>
<div :style="styleObj">
6.绑定style对象
</div>
<hr>
<div>
<input type="checkbox" id="isOk" v-model="isOk">
<label for="isOk">isOk={{isOk}}</label>
</div>
</div>
<style>
.one{
color: red;
}
.two{
font-size: 150%;
}
</style>
</body>
</html>
<script>
var app = new Vue({
el:'#app',
data:{
img:"../assets/img/qq.png",
baidu:'http://www.baidu.com',
one:'one',
two:'two',
isOk:false,
className:'one',
className1:'two',
red:'red',
mix:'100%',
styleObj:{
color:'green',
fontSize:'24px'
}
}
})
</script>