Vue彈窗的兩種實(shí)現(xiàn)方式實(shí)例詳解
方法一 使用.sync修飾符
element就是使用的這種方式,實(shí)現(xiàn)方式如下:
父組件:
<template>
<div id="demo">
<test-model :show.sync="showFlag"></test-model>
</div>
</template>
<script>
import testModel from 'src/components/testModel'
export default {
data(){
return{
showFlag: false
}
},
components: {
testModel,
}
}
</script>
<style lang="scss" scoped>
</style>子組件:
<template>
<div v-if="show">
<button @click="closeShow"></button>
</div>
</template>
<script>
export default {
data(){
return{
}
},
props: ["show"],
methods: {
closeShow() {
this.$emit("update:show",false);
}
},
}
</script>
<style lang="scss" scoped>
</style>子組件通過(guò)this.$emit("update:show",false); 可以直接將父組件傳過(guò)來(lái)的show值改變,從而達(dá)到顯示隱藏的目的。
方法二 使用v-model
父組件
<template>
<div id="demo">
<test-model v-model="show"></test-model>
</div>
</template>
<script>
import testModel from 'src/components/testModel'
export default {
data(){
return{
show: false
}
},
components: {
testModel,
}
}
</script>
<style lang="scss" scoped>
</style>子組件
<template>
<div v-if="value">
<button @click="closeShow"></button>
</div>
</template>
<script>
export default {
data(){
return{
}
},
props: ["value"],
model: {
prop: 'value',
event: 'balabala'
},
methods: {
changeShow() {
this.$emit("balabala",false);
}
},
}
</script>
<style lang="scss" scoped>
</style>官方文檔里有寫,一個(gè)組件上的v-model默認(rèn)會(huì)利用名為value的 prop 和名為input的事件,但是像單選框、復(fù)選框等類型的輸入控件可能會(huì)將value特性用于不同的目的。model選項(xiàng)可以用來(lái)避免這樣的沖突,所以上面的子組件里,我們用balabala來(lái)替換掉了原本的input事件,所以在$emit的時(shí)候,里面的事件名應(yīng)為balabala,否則默認(rèn)為input.
到此這篇關(guān)于Vue彈窗的兩種實(shí)現(xiàn)方式的文章就介紹到這了,更多相關(guān)vue彈窗實(shí)現(xiàn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- vue使用多級(jí)彈窗(Dialog)出現(xiàn)蒙版遮罩問(wèn)題及解決
- vue中PC端使用高德地圖實(shí)現(xiàn)搜索定位、地址標(biāo)記、彈窗顯示定位詳情(完整實(shí)例)
- Vue3使用element-plus實(shí)現(xiàn)彈窗效果
- Vue利用openlayers實(shí)現(xiàn)點(diǎn)擊彈窗的方法詳解
- vue實(shí)現(xiàn)彈窗引用另一個(gè)頁(yè)面窗口
- vue中實(shí)現(xiàn)點(diǎn)擊空白區(qū)域關(guān)閉彈窗的兩種方法
- Vue按照順序?qū)崿F(xiàn)多級(jí)彈窗效果 附Demo
相關(guān)文章
使用vue自定義如何實(shí)現(xiàn)Tree組件和拖拽功能
這篇文章主要介紹了使用vue自定義如何實(shí)現(xiàn)Tree組件和拖拽功能,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-12-12
Vue用mixin合并重復(fù)代碼的實(shí)現(xiàn)
這篇文章主要介紹了Vue用mixin合并重復(fù)代碼的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11
vue或css動(dòng)畫實(shí)現(xiàn)列表向上無(wú)縫滾動(dòng)
這篇文章主要為大家詳細(xì)介紹了vue或css動(dòng)畫實(shí)現(xiàn)列表向上無(wú)縫滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
通過(guò)cordova將vue項(xiàng)目打包為webapp的方法
這篇文章主要介紹了通過(guò)cordova將vue項(xiàng)目打包為webapp的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-02-02
新手vue構(gòu)建單頁(yè)面應(yīng)用實(shí)例代碼
本篇文章主要介紹了新手vue構(gòu)建單頁(yè)面應(yīng)用實(shí)例代碼,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09
antd中table展開行默認(rèn)展示,且不需要前邊的加號(hào)操作
這篇文章主要介紹了antd中table展開行默認(rèn)展示,且不需要前邊的加號(hào)操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-11-11

