前端在el-dialog中嵌套多個el-dialog代碼實現(xiàn)
一、應用場景
- 應用場景:需要點擊按鈕后彈出第一層對話框,在第一層對話框中填寫內(nèi)容后,再點擊確認彈出第二層對話框,且需將第一層填入的內(nèi)容傳遞給第二層,再第二層時彈出提示,再通過點擊第二層的確認按鈕進行請求接口,將第一層的內(nèi)容 傳遞給后端



二、代碼實現(xiàn)
<template>
<table>
<template #action>
<el-button type="success" @click="outerVisible = true">
修改備注
</el-button>
</template>
</table>
<el-dialog v-model="outerVisible" title="提示" draggable width="520px">
<!-- #default:自定義內(nèi)容均可寫在此處 -->
<template #default>
<!-- 這里的el-form是外層dialog中的表單 -->
<el-form label-width="100px" :model="note">
<el-form-item label="備注" prop="note">
<el-input v-model="note" />
</el-form-item>
</el-form>
<!-- 內(nèi)嵌的dialog -->
<el-dialog
v-model="innerVisible"
width="30%"
title="提示"
append-to-body
draggable
>
<span>請確認是否發(fā)送數(shù)據(jù)?</span>
<template #footer>
<div class="dialog-footer">
<el-button @click="closeAllDialog">關閉</el-button>
<el-button type="primary" @click="saveConfirm"> 確認 </el-button>
</div>
</template>
</el-dialog>
</template>
<template #footer>
<div class="dialog-footer">
<el-button @click="outerVisible = false">{{
t('global.action.close')
}}</el-button>
<el-button type="primary" @click="innerVisible = true">
{{ t('global.action.confirm') }}
</el-button>
</div>
</template>
</el-dialog>
</template>
<script lang="ts">
import { defineComponent, reactive } from 'vue';
import { Data, sendData } from '@/services/listData';
interface ViewState {
selectedOrders: Data[];
note: string;
outerVisible: boolean;
innerVisible: boolean;
}
export default defineComponent({
name: 'list',
components: {},
setup() {
const state = reactive<ViewState>({
note: '',
outerVisible: false,
innerVisible: false,
});
// 關閉內(nèi)層對話框的同時也關閉外層的對話框
function closeAllDialog() {
// 關閉內(nèi)層的對話框
state.innerVisible = false;
// 關閉外層的對話框
state.outerVisible = false;
}
function saveConfirm() {
// 所勾選的id
const selectedIds = selection.value.map(i => {
return i.id;
});
// 這里寫請求接口的邏輯
sendData(selectedIds, state.note)
.then(() => {
ElMessage({
type: 'success',
message: '發(fā)送成功',
});
})
.finally(() => {
state.innerVisible = false;
state.outerVisible = false;
});
}
return {
...toRefs(state),
saveConfirm,
closeAllDialog,
};
},
});
</script>
<style scoped lang="scss"></style>附:el-dialog嵌套el-dialog問題
?定要?級 el-dialog :modal-append-to-body=“false”
?級 el-dialog 同時加上 :append-to-body=“true”
含義:
- modal-append-to-body 遮罩層是否插?? body 元素上,若為 false,則遮罩層會插?? Dialog的?元素上
- append-to-body Dialog ?身是否插?? body 元素上。嵌套的 Dialog 必須指定定該屬性并賦值為true
總結(jié)
到此這篇關于前端在el-dialog中嵌套多個el-dialog的文章就介紹到這了,更多相關前端嵌套多個el-dialog內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Element-ui table中過濾條件變更表格內(nèi)容的方法
下面小編就為大家分享一篇Element-ui table中過濾條件變更表格內(nèi)容的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03
vue3:vue2中protoType更改為config.globalProperties問題
這篇文章主要介紹了vue3:vue2中protoType更改為config.globalProperties問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue中Axios配置不同的baseURL,請求不同的域名接口方式
這篇文章主要介紹了Vue中Axios配置不同的baseURL,請求不同的域名接口方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
vue3使用別名報錯問題的解決辦法(vetur插件報錯問題)
最近在寫一個購物網(wǎng)站使用vue,使用中遇到了問題,下面這篇文章主要給大家介紹了關于vue3使用別名報錯問題的解決辦法,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2022-07-07
Vue?socket.io模塊實現(xiàn)聊天室流程詳解
vue-socket.io其實是在socket.io-client(在瀏覽器和服務器之間實現(xiàn)實時、雙向和基于事件的通信)基礎上做了一層封裝,將socket掛載到vue實例上,同時可使用sockets對象輕松實現(xiàn)組件化的事件監(jiān)聽,在vue項目中使用起來更方便2022-12-12
vue實現(xiàn)el-menu和el-tab聯(lián)動的示例代碼
本文主要介紹了vue實現(xiàn)el-menu和el-tab聯(lián)動的示例代碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-04-04

