目录
1. v-bind指令
1.1 v-bind的基本使用
<body>
<div id="app">
<!-- 错误的做法这里不能使用Mustache语法 -->
<!-- <img v-bind:src="{
{imgURL}}" alt=""> -->
<!-- 正确的做法使用v-bind指令 -->
<img v-bind:src="imgURL" alt="">
<a v-bind:href="aHerf"></a>
<!-- 语法糖写法 --> <!-- 就是在不改变原有结构和功能下简化写法 -->
<img :src="imgURL" alt="">
<a :href="aHerf"></a>
</div>
<script src="vue.js"></script>
<script>
const app = new Vue({
el:"#app",
data:{
message:"你好啊",
imgURL:"https://blog.csdn.net",
aHerf:"http://www.baidu.com"
}
})
</script>
</body>
1.2 v-bind动态绑定class(对象语法)
<body>
<div id="app">
<!-- <h2 class="active">{
{message}}</h2>
<h2 :class="active">{
{message}}</h2> -->
<!-- 动态绑定class对象用法 -->
<!-- <h2 :class="{key1:value1,key2:value2}">{
{message}}</h2>
<h2 :class="{类名1:true,类名2:boolean}">{
{message}}</h2> -->
<!-- :class="{active:isActive}" isActive为true类名才生效 -->
<h2 class="title" :class="{active:isActive}">{
{message}}</h2>
<h2 class="title" :class="getClasses()">{
{message}}</h2>
<button @click="change">点击变色</button>
</div>
<script src="vue.js"></script>
<script>
const app = new Vue({
el:"#app",
data:{
message:"你好啊",
active:"active",
isActive:true
},
methods: {
change(){
this.isActive = !this.isActive
},
getClasses(){
return {active:this.isActive}
}
},
})
</script>
</body>
2. v-for的基本使用
<body>
<div id="app">