vue中el-dialog打開與關(guān)閉的幾種方式
第一種,使用 update:visible
父組件
<child-dialog :visible="visible"></child-dialog>
子組件
<template>
<el-dialog title="接口實(shí)例詳情" @open="onOpen" @close="onClose">
// 主體內(nèi)容
<div slot="footer">
<el-button @click="close">取消</el-button>
<el-button type="primary" @click="handelConfirm">確定</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
props: {
visible: Boolean
},
methods: {
// 彈出框打開事件
onOpen() {},
onClose() {
this.$refs['GxptServiceDialog'].resetFields()
},
close() {
this.$emit('update:visible', false)
},
handelConfirm() {
this.$refs['gialog'].validate(valid => {
if (!valid) return
this.close()
})
}
}
}
第二種 ref
父組件
<child-list></child-list> <child-dialog ref="dialog"></child-dialog>
this. r e f s . d i a l o g . v i s i b l e = t r u e ; 在兄弟組件中 t h i s . refs.dialog.visible = true; 在兄弟組件中 this. refs.dialog.visible=true;在兄弟組件中this.parent.$refs.dialog.visible = true;
子組件
<template>
<el-dialog :title="title"
:visible.sync="visible"
:width="width"
append-to-body
:close-on-click-modal="false"
@close="close">
<span slot="footer" class="dialog-footer">
<div style="text-align: right;padding-bottom:10px">
<el-button size="medium" type="primary" @click.native="handleSave()">確 定</el-button>
<el-button size="medium" @click.native="close">取 消</el-button>
</div>
</span>
</el-dialog>
</template>
<script>
export default {
data() {
return {
visible: false,
}
},
methods: {
close() {
this.visible = false;
}
}
}
第三種 兄弟 bus
父組件
<child-list></child-list> <child-dialog></child-dialog>
import Vue from 'vue' export default new Vue()
子組件
<template>
<el-dialog title="接口實(shí)例詳情" @open="onOpen" @close="onClose" :visible.sync="visible">
// 主體內(nèi)容
<div slot="footer">
<el-button @click="close">取消</el-button>
<el-button type="primary" @click="handelConfirm">確定</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
return {
visible: false
}
},
mounted() {
bus.$on('isVisible', data => {
this.visible = data
})
},
methods: {
// 彈出框打開事件
onOpen() {},
onClose() {
this.$refs['dialog'].resetFields()
},
close() {
this.$emit('update:visible', false)
},
handelConfirm() {
this.$refs['gialog'].validate(valid => {
if (!valid) return
this.close()
})
}
}
}
使用
bus.$emit(‘isVisible’, true)
控制彈出框打開與關(guān)閉
到此這篇關(guān)于vue中el-dialog打開與關(guān)閉的幾種方式的文章就介紹到這了,更多相關(guān)vue el-dialog打開與關(guān)閉內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue-cli搭建spa項(xiàng)目的項(xiàng)目實(shí)踐
本文主要介紹了Vue-cli搭建spa項(xiàng)目的項(xiàng)目實(shí)踐,首先,你需要安裝Vue CLI,然后通過它創(chuàng)建新項(xiàng)目,接著,選擇和配置適當(dāng)?shù)牟寮鸵蕾図?xiàng),以完善你的SPA項(xiàng)目,感興趣的可以了解一下2023-09-09
詳解element-ui級(jí)聯(lián)菜單(城市三級(jí)聯(lián)動(dòng)菜單)和回顯問題
這篇文章主要介紹了詳解element-ui級(jí)聯(lián)菜單(城市三級(jí)聯(lián)動(dòng)菜單)和回顯問題,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Vue ElementUi同時(shí)校驗(yàn)多個(gè)表單(巧用new promise)
這篇文章主要介紹了巧用new promise實(shí)現(xiàn)Vue ElementUi同時(shí)校驗(yàn)多個(gè)表單功能,實(shí)現(xiàn)的方法有很多種,本文給大家?guī)淼氖且环N比較完美的方案,需要的朋友可以參考下2018-06-06
vue實(shí)現(xiàn)移動(dòng)端可拖拽式icon圖標(biāo)
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)移動(dòng)端可拖拽式icon圖標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
webpack+vue.js實(shí)現(xiàn)組件化詳解
vue的開發(fā)體驗(yàn)還是比較愉悅的。首先文檔非常友好,所以上手會(huì)比較快。其次,配合webpack和vue-loader,每個(gè)頁面都是一個(gè).vue文件,寫起來很方便。所以很適合做組件化開發(fā),這篇文章我們就來一起看看webpack+vue.js如何實(shí)現(xiàn)組件化。2016-10-10
vue props對(duì)象validator自定義函數(shù)實(shí)例
今天小編就為大家分享一篇vue props對(duì)象validator自定義函數(shù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11

