目次Vue.js使用this.$confirm换行显示提示信息在写一个简朴的按钮点击确认框信息的时候,发现换行不能用\n。用了< br>发现也是字符串的输出情势 去查了下发现必要使用$createElement来创建 这里我必要显示两行信息。 代码如下: [code]creatNew(){ const h = this.$createElement this.$confirm('提示', { title: '提示', message: h('div', [ h('p', '新建会导致之前设置失效'), h('p', '是否继承新建?') ]), confirmButtonText: '确定', cancelButtonText: '取消' }).then(() => { ....//调用新建方法 }).catch(()=>({}))//不要忘记catch //末了可以.finally(()=>({})) }[/code]解释
Vue的this.$confirm中注意this的指向Vue开发过程中遇到this. confirm( )里面的this失效题目,就是当你想在里面使用data数据的时候,我们每每是 this.dataName这种方式拿到值,但在 this.confirm()里面的this失效题目,就是当你想在里面使用data数据的时候,我们每每是this.dataName这种方式拿到值,但在this. confirm()里面的this失效题目,就是当你想在里面使用data数据的时候,我们每每是this.dataName这种方式拿到值,但在this.confirm()里面的this不是指向当前vue了,以是是取不到data的数据。 解决方法因此我们在使用this.$confirm()前先保存this [code]let _this = this[/code] [code] const _this = this this.$confirm({ title: '當前郵件正文内容爲空', content: h => <div style="color:red;">確認是否發佈?</div>, onOk () { console.log('保存提交的对象', this.objData) _this.loading = true initAxios.saveMail(_this.objData).then((res) => { _this.loading = false if (res.data.code === '200' && res.data.result) { _this.$router.go(-1) // 处置处罚返回必要点两次的题目 _this.$message.success('發佈成功!') } }) }, onCancel () { return false } }) [/code]总结以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。 来源:https://www.jb51.net/javascript/328924fdz.htm 免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |
|手机版|小黑屋|梦想之都-俊月星空
( 粤ICP备18056059号 )|网站地图
GMT+8, 2025-7-2 03:25 , Processed in 0.031426 second(s), 19 queries .
Powered by Mxzdjyxk! X3.5
© 2001-2025 Discuz! Team.