Vue.js中使用this.$confirm换行显示提示信息

在写一个简单的按钮点击确认框信息的时候,发现换行不能用\n。用了< br>发现也是字符串的输出形式

去查了下发现需要使用$createElement来创建

这里我需要显示两行信息。代码如下

creatNew(){
 const h = this.$createElement
        this.$confirm('提示', {
          title: '提示',
          message: h('div', [
            h('p', '新建会导致之前设置失效'),
            h('p', '是否继续新建?')
          ]),
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(() => {
        ....//调用新建方法
        }).catch(()=>({}))//不要忘记catch
        //最后可以.finally(()=>({}))
        }

解释:

h('div')就表示创建一个div标签,
★如果写成h('div',{class:'...'})就可以定义class,如:

 h('i', { class: 'el-icon-question' })

★如果写成下面的,则可以定义props。(以element的弹出框el-tooltip为例)

h('el-tooltip',{props:{
					content: (function() {
                  	return '弹出信息'
                  	})(),
                	placement: 'top'
                	}})

★包含关系用h('div',[...]),如div中包含两个p标签:(可以继续嵌套)

h('div', [
            h('p', '第一个p'),
            h('p', '第二个p')
          ])
简单介绍到这里

————————————————————————————

👉推荐!!!【腾讯云】爆款2核4G云服务器首年74元/年
👉推荐!!!【腾讯云】1核2G5M轻量应用服务器50元/年
【腾讯云】云数据库低至9.9/年!MySQL7.4元/月
【阿里云】ECS云服务器特惠
【阿里云】服务器首购优惠
如果文章对您有帮助,扫个红包码呗

红包码

  • 8
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
使用this.$confirm时,可以使用$createElement来创建多个p标签,并将它们包裹在一个div标签。例如,可以使用以下代码进: ``` const h = this.$createElement; this.$confirm('提示', { title: '提示', message: h('div', [ h('p', '是否将该账号密码重置为初始密码?'), h('p', '成功后将密码设为默认密码,默认密码为用户账号') ]), confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }) .then(() => { resetPasswords(params).then((res) => { if (res.code == 200) { this.$message.success('重置密码成功'); } }); }) .catch(() => { this.$message({ type: 'info', message: '已取消重置密码', }); }); ``` 这样可以在确认框显示文本。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [vue this.$confirm提示的文字](https://blog.csdn.net/weixin_45799001/article/details/125086460)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [confirm提示内容时问题](https://blog.csdn.net/qq_43432057/article/details/116981331)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [js使用小技巧](https://download.csdn.net/download/qq_17486363/7619983)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值