Vue消息提示框的使用

Vue消息提示框的使用

this.$message
this.$message({
	message: "请输入原因",
	//type 取值 success(成功) /warning(警告)/info(消息)/error(错误)/;
	type: "warning",
});

//type 取值 success(成功) /warning(警告)/info(消息)/error(错误)/;
this.$message.success("这是提示消息")
this.$confirm
this.$confirm('完成信息核对, 确认提交?', '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
}).then(() => {
    //略,数据接口处理
    this.$message({
        message: '必填项未填写完整',
        type: 'error'
    })
}).catch(() => {
})
this.$confirm提示内容换行
// 1.把写的提示内容需要换行的地方分成数组 confirmText
const confirmText = ['是否确认删除1011',  '是否确认删除1012'] 
// 2.创建一个新数组
const newDatas = []
// 3.创建虚拟节点
const h = this.$createElement
// 4.循环输出数组的每条信息
for (const i in confirmText) {
//将数组中的每条信息进行用p标签填充
	newDatas.push(h('p', null, confirmText[i]))
}
this.$confirm(
    '提示',
    {
        title: '提示',
        //将所有信息放在div标签中
        message: h('div', null, newDatas),
        showCancelButton: true,
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
    }
).then(() => {
})

组件实例的$createElement属性是一个具有特殊功能的函数,作用与渲染函数的第一个参数相同,用来定义虚拟节点。

这里用到了vue $createElement这个方法,此方法各个参数的含义和用法如下:

h('div', {}, [
    h('p', {}, '是否确认删除1011'),
    h('p', {}, '是否确认删除1012'),
])
  1. 第一个参数,为标签,即创建的节点元素的标签是什么

  2. 第二个参数是几点元素的属性配置,例如class,style等等

  3. 第三个元素是节点元素的内容

    例如如下代码:

h('div', {class: 'test'}, [
    h('p', {}, '是否确认删除1011'),
	h('p', {}, '是否确认删除1012'),
])

生成的divdom元素上多了class属性

h('div', {
    style: {
    	color: 'green'
    }
    }, [
    h('p', {}, '是否确认删除1011'),
    h('p', {}, '是否确认删除1012'),
])

对话框内容的字体将会变成了绿色。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值