vue01

添加事件

<div class="you">

<input type="text" v-model="list">

<button v-on:click="nam">添加</button>

<ul>

<li v-for="(vel,index) in sg">{{vel}}<button v-on:click="men(index)">刪除</button>

</li>

</ul>

</div>

new Vue({

el:'.you',

data:{

sg:['dd','hs','md'],

list:''

},

methods:{

nam:function(){

this.sg.push(this.list),

this.list=''

},

men:function(ind){

this.sg.splice(ind,1)

}

}

})



v-bind

<div class="you">

<img v-bind:scr="url" alt="" @click="chg">

</div>

new Vue({

el:'.you',

data:{

url:'img/1.jpg',

hef:'img/2.jpg'

},

methods:{

chg:function(){

this.url=this.hef

}

}

})



v-show/v-if

<div class="you">

<p>此內(nèi)容可見</p>

<p v-show=!see>v-if此內(nèi)容不可見</p>

<p>此內(nèi)容可見</p>

<p v-if=!see>v-if此內(nèi)容不可見</p>

</div>

new Vue({

el:'.you',

data:{

see:true

}

})



點(diǎn)擊隱藏

<style>

.box{

width:30px;

height:30px;

background:red;

}

</style>

<div class="you">

<button @click="chg">點(diǎn)擊隱藏</button>

<div class="box" v-show=see>

</div>

</div>

new Vue({

el:'.you',

data:{

see:true

},

methods:{

chg:function(){

this.see=!this.see

}

}

})



切換圖片

<style>

ul{

overflow:hidden;

}

li{

width:600px;

text-align:center;

list-style:none;

border:1px solid black;

float:left;

}

</style>

<div class="you">

<img v-bind:src="url" alt="">

<ul>

<li v-for="(value,index) in arr" @click="chg(index)">{{index+1}}</li>

</ul>

</div>

new Vue({

el:'.you',

data:{

url:'img/1.jpg',

arr:['img/1.jpg','img/2.jpg','img/3.jpg','img/4.jpg','img/5.jpg']

},

methods:{

chg:function(ind){

this.url=this.arr[ind]

}

}

})



display:none與visibility:hidden的區(qū)別

display:none是徹底隱藏了,不在文檔流中占位,瀏覽器也不會讀取。

visibility:hidden只是看不到了,而它在文檔流中占位,瀏覽器也會讀取。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容