vue中的v-show,v-if,v-bind的使用示例詳解
vue第四課:v-show,v-if,v-bind的使用
1,v-show指令
根據(jù)表達(dá)式的真假,切換元素的顯示和隱藏如:廣告,遮罩層等
<div id='app'>
<input type="button" value="切換顯示狀態(tài)" @click="changeIsshow">
<input type="button" value="增加年齡" @click="addage">
<img v-show="isshow" width="200px" height="200px"
src="https://guangzan.gitee.io/imagehost/Illustrations/summer.png" />
<img v-show="age>=18" width="200px" height="200px"
src="https://guangzan.gitee.io/imagehost/Illustrations/summer.png" />
</div>
<script>
Vue.config.productionTip = false //阻止vue在啟動(dòng)時(shí)生成生產(chǎn)提示。
var app = new Vue({
el: '#app',
data: {
isshow: false,
age: 17,
},
methods: {
changeIsshow: function () {
this.isshow = !this.isshow;
},
addage: function () {
this.age++;
}
},
})
</script>2,v-if指令
根據(jù)表達(dá)式的真假,切換元素的顯示和隱藏(操作dom元素),頻繁操作用v-show,反之用v-if
<div id='app'>
<input type="button" value="顯示/隱藏" @click="changehide">
<p v-if="isshow">卷完后端卷前端</p>
<p v-show="isshow">卷完后端卷前端-vshow</p>
</div>
<script>
Vue.config.productionTip = false //阻止vue在啟動(dòng)時(shí)生成生產(chǎn)提示。
var app = new Vue({
el: '#app',
data: {
isshow:false,
},
methods: {
changehide:function(){
this.isshow = !this.isshow;
}
},
})
</script>3,v-bind指令
設(shè)置元素的屬性比如(src,title,class等)v-bind:屬性名=表達(dá)式 v-bind:可簡寫成 :class="" 省掉v-bind
<style>
.active{
border: 1px solid red;
}
</style>
<div id='app'>
<img v-bind:src="imgsrc" width="200px" height="200px" alt=""/><br>
<img :src="imgsrc" width="200px" height="200px" alt="" :title="title+'!!!'" :class="isactive?'active':''" @click="togactive"/>
<img :src="imgsrc" width="200px" height="200px" alt="" :title="title+'!!!'" :class="{active:isactive}" @click="togactive"/>
</div>
<script>
Vue.config.productionTip = false //阻止vue在啟動(dòng)時(shí)生成生產(chǎn)提示。
var app = new Vue({
el: '#app',
data: {
imgsrc:"https://guangzan.gitee.io/imagehost/Illustrations/summer.png",
title:"vUE卷你",
isactive:false,
},
methods: {
togactive:function(){
this.isactive = !this.isactive;
}
},
})
</script>到此這篇關(guān)于vue中的v-show,v-if,v-bind的使用的文章就介紹到這了,更多相關(guān)vue v-show,v-if,v-bind使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于vue實(shí)現(xiàn)動(dòng)態(tài)Tab標(biāo)簽頁功能
這篇文章主要介紹了如何基于vue實(shí)現(xiàn)動(dòng)態(tài)Tab標(biāo)簽頁功能,文中通過代碼示例和圖文結(jié)合的方式給大家講解的非常詳細(xì),對大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-09-09
關(guān)于在vue中實(shí)現(xiàn)過渡動(dòng)畫的代碼示例
Vue是一款流行的前端框架,支持過渡動(dòng)畫的實(shí)現(xiàn)是其中的一項(xiàng)重要特性,在Vue中,使用過渡動(dòng)畫可以為用戶提供更加友好的用戶體驗(yàn),下面我將為大家介紹一下子如何在Vue中實(shí)現(xiàn)過渡動(dòng)畫,需要的朋友可以參考下2023-06-06
npm run serve運(yùn)行vue項(xiàng)目時(shí)報(bào)錯(cuò):Error: error:0308010C
這篇文章主要介紹了npm run serve運(yùn)行vue項(xiàng)目時(shí),出現(xiàn)報(bào)錯(cuò):Error: error:0308010C:digital envelope routines::unsupported的解決方法,文中有詳細(xì)的解決方法,需要的朋友可以參考下2024-04-04
詳解Jest結(jié)合Vue-test-utils使用的初步實(shí)踐
這篇文章主要介紹了詳解Jest結(jié)合Vue-test-utils使用的初步實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06

