Element MessageBox彈框的具體使用
組件—彈框
消息提示
<template> <el-button type="text" @click="open">點(diǎn)擊打開 Message Box</el-button> </template> <script> export default { methods: { open() { this.$alert('這是一段內(nèi)容', '標(biāo)題名稱', { confirmButtonText: '確定', callback: action => { this.$message({ type: 'info', message: `action: ${ action }` }); } }); } } } </script>
確認(rèn)消息
<template> <el-button type="text" @click="open">點(diǎn)擊打開 Message Box</el-button> </template> <script> export default { methods: { open() { this.$alert('這是一段內(nèi)容', '標(biāo)題名稱', { confirmButtonText: '確定', callback: action => { this.$message({ type: 'info', message: `action: ${ action }` }); } }); } } } </script>
提交內(nèi)容
<template> <el-button type="text" @click="open">點(diǎn)擊打開 Message Box</el-button> </template> <script> export default { methods: { open() { this.$prompt('請(qǐng)輸入郵箱', '提示', { confirmButtonText: '確定', cancelButtonText: '取消', inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/, inputErrorMessage: '郵箱格式不正確' }).then(({ value }) => { this.$message({ type: 'success', message: '你的郵箱是: ' + value }); }).catch(() => { this.$message({ type: 'info', message: '取消輸入' }); }); } } } </script>
自定義
<template> <el-button type="text" @click="open">點(diǎn)擊打開 Message Box</el-button> </template> <script> export default { methods: { open() { const h = this.$createElement; this.$msgbox({ title: '消息', message: h('p', null, [ h('span', null, '內(nèi)容可以是 '), h('i', { style: 'color: teal' }, 'VNode') ]), showCancelButton: true, confirmButtonText: '確定', cancelButtonText: '取消', beforeClose: (action, instance, done) => { if (action === 'confirm') { instance.confirmButtonLoading = true; instance.confirmButtonText = '執(zhí)行中...'; setTimeout(() => { done(); setTimeout(() => { instance.confirmButtonLoading = false; }, 300); }, 3000); } else { done(); } } }).then(action => { this.$message({ type: 'info', message: 'action: ' + action }); }); } } } </script>
使用 HTML 片段
<template> <el-button type="text" @click="open">點(diǎn)擊打開 Message Box</el-button> </template> <script> export default { methods: { open() { this.$alert('<strong>這是 <i>HTML</i> 片段</strong>', 'HTML 片段', { dangerouslyUseHTMLString: true }); } } } </script>
區(qū)分取消與關(guān)閉
<template> <el-button type="text" @click="open">點(diǎn)擊打開 Message Box</el-button> </template> <script> export default { methods: { open() { this.$alert('<strong>這是 <i>HTML</i> 片段</strong>', 'HTML 片段', { dangerouslyUseHTMLString: true }); } } } </script>
居中布局
<template> <el-button type="text" @click="open">點(diǎn)擊打開 Message Box</el-button> </template> <script> export default { methods: { open() { this.$confirm('此操作將永久刪除該文件, 是否繼續(xù)?', '提示', { confirmButtonText: '確定', cancelButtonText: '取消', type: 'warning', center: true }).then(() => { this.$message({ type: 'success', message: '刪除成功!' }); }).catch(() => { this.$message({ type: 'info', message: '已取消刪除' }); }); } } } </script>
全局方法
單獨(dú)引用
Options
到此這篇關(guān)于Element MessageBox彈框的具體使用的文章就介紹到這了,更多相關(guān)Element MessageBox彈框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue2.0 移動(dòng)端實(shí)現(xiàn)下拉刷新和上拉加載更多的示例
本篇文章主要介紹vue2.0 移動(dòng)端實(shí)現(xiàn)下拉刷新和上拉加載更多的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04解讀element?el-upload上傳的附件名稱不顯示?file-list賦值
這篇文章主要介紹了解讀element?el-upload上傳的附件名稱不顯示?file-list賦值問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10Vue中img的src是動(dòng)態(tài)渲染時(shí)不顯示的解決
今天小編就為大家分享一篇Vue中img的src是動(dòng)態(tài)渲染時(shí)不顯示的解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11Vue項(xiàng)目總結(jié)之webpack常規(guī)打包優(yōu)化方案
這篇文章主要介紹了vue項(xiàng)目總結(jié)之webpack常規(guī)打包優(yōu)化方案,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06