vue中el-dialog打開與關(guān)閉的幾種方式
第一種,使用 update:visible
父組件
<child-dialog :visible="visible"></child-dialog>
子組件
<template>
<el-dialog title="接口實例詳情" @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="接口實例詳情" @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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解element-ui級聯(lián)菜單(城市三級聯(lián)動菜單)和回顯問題
這篇文章主要介紹了詳解element-ui級聯(lián)菜單(城市三級聯(lián)動菜單)和回顯問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Vue ElementUi同時校驗多個表單(巧用new promise)
這篇文章主要介紹了巧用new promise實現(xiàn)Vue ElementUi同時校驗多個表單功能,實現(xiàn)的方法有很多種,本文給大家?guī)淼氖且环N比較完美的方案,需要的朋友可以參考下2018-06-06
vue實現(xiàn)移動端可拖拽式icon圖標(biāo)
這篇文章主要為大家詳細(xì)介紹了vue實現(xiàn)移動端可拖拽式icon圖標(biāo),文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-03-03
vue props對象validator自定義函數(shù)實例
今天小編就為大家分享一篇vue props對象validator自定義函數(shù)實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11

