Element Dialog對(duì)話(huà)框的使用示例
組件— 對(duì)話(huà)框
基本用法


<el-button type="text" @click="dialogVisible = true">點(diǎn)擊打開(kāi) Dialog</el-button>
<el-dialog
title="提示"
:visible.sync="dialogVisible"
width="30%"
:before-close="handleClose">
<span>這是一段信息</span>
<span slot="footer" class="dialog-footer">
<el-button @click="dialogVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogVisible = false">確 定</el-button>
</span>
</el-dialog>
<script>
export default {
data() {
return {
dialogVisible: false
};
},
methods: {
handleClose(done) {
this.$confirm('確認(rèn)關(guān)閉?')
.then(_ => {
done();
})
.catch(_ => {});
}
}
};
</script>

自定義內(nèi)容



<!-- Table -->
<el-button type="text" @click="dialogTableVisible = true">打開(kāi)嵌套表格的 Dialog</el-button>
<el-dialog title="收貨地址" :visible.sync="dialogTableVisible">
<el-table :data="gridData">
<el-table-column property="date" label="日期" width="150"></el-table-column>
<el-table-column property="name" label="姓名" width="200"></el-table-column>
<el-table-column property="address" label="地址"></el-table-column>
</el-table>
</el-dialog>
<!-- Form -->
<el-button type="text" @click="dialogFormVisible = true">打開(kāi)嵌套表單的 Dialog</el-button>
<el-dialog title="收貨地址" :visible.sync="dialogFormVisible">
<el-form :model="form">
<el-form-item label="活動(dòng)名稱(chēng)" :label-width="formLabelWidth">
<el-input v-model="form.name" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="活動(dòng)區(qū)域" :label-width="formLabelWidth">
<el-select v-model="form.region" placeholder="請(qǐng)選擇活動(dòng)區(qū)域">
<el-option label="區(qū)域一" value="shanghai"></el-option>
<el-option label="區(qū)域二" value="beijing"></el-option>
</el-select>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="dialogFormVisible = false">取 消</el-button>
<el-button type="primary" @click="dialogFormVisible = false">確 定</el-button>
</div>
</el-dialog>
<script>
export default {
data() {
return {
gridData: [{
date: '2016-05-02',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1518 弄'
}, {
date: '2016-05-04',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1518 弄'
}, {
date: '2016-05-01',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1518 弄'
}, {
date: '2016-05-03',
name: '王小虎',
address: '上海市普陀區(qū)金沙江路 1518 弄'
}],
dialogTableVisible: false,
dialogFormVisible: false,
form: {
name: '',
region: '',
date1: '',
date2: '',
delivery: false,
type: [],
resource: '',
desc: ''
},
formLabelWidth: '120px'
};
}
};
</script>
嵌套的 Dialog


<template>
<el-button type="text" @click="outerVisible = true">點(diǎn)擊打開(kāi)外層 Dialog</el-button>
<el-dialog title="外層 Dialog" :visible.sync="outerVisible">
<el-dialog
width="30%"
title="內(nèi)層 Dialog"
:visible.sync="innerVisible"
append-to-body>
</el-dialog>
<div slot="footer" class="dialog-footer">
<el-button @click="outerVisible = false">取 消</el-button>
<el-button type="primary" @click="innerVisible = true">打開(kāi)內(nèi)層 Dialog</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
return {
outerVisible: false,
innerVisible: false
};
}
}
</script>
居中布局


<template>
<el-button type="text" @click="outerVisible = true">點(diǎn)擊打開(kāi)外層 Dialog</el-button>
<el-dialog title="外層 Dialog" :visible.sync="outerVisible">
<el-dialog
width="30%"
title="內(nèi)層 Dialog"
:visible.sync="innerVisible"
append-to-body>
</el-dialog>
<div slot="footer" class="dialog-footer">
<el-button @click="outerVisible = false">取 消</el-button>
<el-button type="primary" @click="innerVisible = true">打開(kāi)內(nèi)層 Dialog</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
return {
outerVisible: false,
innerVisible: false
};
}
}
</script>

Attributes

Slot
Events

Element 對(duì)話(huà)框簡(jiǎn)單使用
官方文檔介紹的是頁(yè)內(nèi)對(duì)話(huà)框,但沒(méi)有基于組件的對(duì)話(huà)框,這里記錄一下,原理就是父子傳值是否顯示
父頁(yè)導(dǎo)入組件
<template>
<div class="home">
<el-button @click="btnAdd">添加用戶(hù)</el-button>
<Dialog :visible.sync="visible" title="添加用戶(hù)"></Dialog>
</div>
</template>
<script>
import Dialog from "../components/dialog";
export default {
name: 'Home',
components: {
Dialog
},
data() {
return {
visible: false
}
},
methods: {
btnAdd() {
this.visible = true
}
}
}
</script>
對(duì)話(huà)框
<template>
<div>
<el-dialog
v-bind="$attrs"
v-on="$listeners"
@open="onOpen"
@close="onClose"
:title="title"
對(duì)話(huà)框打開(kāi)后是否可以點(diǎn)擊后邊灰色區(qū)域關(guān)閉對(duì)話(huà)框
:close-on-click-modal='false'>
<el-row :gutter="15">
<el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
<el-col :span="23">
<el-form-item label="姓名" prop="userName">
<el-input v-model="formData.userName" placeholder="請(qǐng)輸入姓名" :maxlength="50" clearable
prefix-icon='el-icon-user-solid' :style="{width: '100%'}"></el-input>
</el-form-item>
</el-col>
<el-col :span="23">
<el-form-item label="性別" prop="sex">
<el-radio-group v-model="formData.sex" size="medium">
<el-radio v-for="(item, index) in sexOptions" :key="index" :label="item.value"
:disabled="item.disabled">{{item.label}}
</el-radio>
</el-radio-group>
</el-form-item>
</el-col>
<el-col :span="23">
<el-form-item label="生日" prop="birthday">
<el-date-picker v-model="formData.birthday" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
:style="{width: '100%'}" placeholder="請(qǐng)選擇生日" clearable></el-date-picker>
</el-form-item>
</el-col>
</el-form>
</el-row>
<div slot="footer">
<el-button @click="close">取消</el-button>
<el-button type="primary" @click="handelConfirm">確定</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
export default {
inheritAttrs: false,
props: {
title: String
},
data() {
return {
formData: {
userName: undefined,
sex: 3,
birthday: null,
},
rules: {
userName: [{
required: true,
message: '請(qǐng)輸入姓名',
trigger: 'blur'
}],
sex: [{
required: true,
message: '性別不能為空',
trigger: 'change'
}],
birthday: [{
required: true,
message: '請(qǐng)選擇生日',
trigger: 'change'
}],
},
sexOptions: [{
"label": "男",
"value": 1
}, {
"label": "女",
"value": 2
}, {
"label": "保密",
"value": 3
}],
}
},
methods: {
onOpen() {
//打開(kāi)對(duì)話(huà)框執(zhí)行
},
onClose() {
//關(guān)閉對(duì)話(huà)框執(zhí)行清除以上字段內(nèi)容
this.$refs['elForm'].resetFields()
},
close() {
//手工調(diào)用關(guān)閉,顯示狀態(tài)為隱藏
this.$emit('update:visible', false)
},
handelConfirm() {
this.$refs['elForm'].validate(valid => {
if (valid) {
//點(diǎn)擊確定后執(zhí)行驗(yàn)證并執(zhí)行方法,執(zhí)行完畢后調(diào)用close()方法
this.$message.success({
message: "成功了"
})
this.close()
}
})
}
}
}
</script>
執(zhí)行效果

到此這篇關(guān)于Element Dialog對(duì)話(huà)框的使用示例的文章就介紹到這了,更多相關(guān)Element Dialog對(duì)話(huà)框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue-router兩種模式區(qū)別及使用注意事項(xiàng)詳解
這篇文章主要介紹了vue-router兩種模式區(qū)別及使用注意事項(xiàng),結(jié)合實(shí)例形式詳細(xì)分析了vue-router兩種模式hash模式與history模式的區(qū)別、用法與操作注意事項(xiàng),需要的朋友可以參考下2019-08-08
解決vue項(xiàng)目,npm run build后,報(bào)路徑錯(cuò)的問(wèn)題
這篇文章主要介紹了解決vue項(xiàng)目,npm run build后,報(bào)路徑錯(cuò)的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-08-08
VueQuillEditor富文本上傳圖片(非base64)
這篇文章主要介紹了VueQuillEditor富文本上傳圖片(非base64),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
前端使用vue實(shí)現(xiàn)token無(wú)感刷新的三種方案解析
這篇文章主要為大家介紹了前端使用vue實(shí)現(xiàn)token無(wú)感刷新的三種方案詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-06-06
vue實(shí)現(xiàn)錨點(diǎn)跳轉(zhuǎn)之scrollIntoView()方法詳解
這篇文章主要介紹了vue實(shí)現(xiàn)錨點(diǎn)跳轉(zhuǎn)之scrollIntoView()方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
vue實(shí)現(xiàn)圖書(shū)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)圖書(shū)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12
詳解基于vue-cli3快速發(fā)布一個(gè)fullpage組件
這篇文章主要介紹了詳解基于vue-cli3快速發(fā)布一個(gè)fullpage組件,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-03-03
如何使用HBuilderX把vue項(xiàng)目打包成apk
這篇文章主要介紹了如何使用HBuilderX把vue項(xiàng)目打包成apk,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07

