element组件message消息提示渲染html片段

739 阅读1分钟

方法一、使用文档中的配置

let message = '提示信息<br>错误提示'
this.$message({
  type: 'error',
  message: message,
  dangerouslyUseHTMLString: true   // 把message当做html片段处理,根据<br>标签实现换行
});

方法二、使用h函数(creatElement方法)

const h = this.$createElement;
this.$message({
    message: h('p', null, [
      h('strong', null, '内容可以是'),
      h('i', {style: 'color: red'}, 'VNode')
    ]),
    type: 'error'
})

使用h函数可以在table表头中加入相应的代码, 例如:在“姓名”栏加上图标

<el-table-column prop="address" label="姓名" :render-header="renderHeader"></el-table-column>
methods: { 
    renderHeader (h,{column}) {   
        return h(
            'div',[
                h('span', column.label), 
                h('i', {
                    class:'el-icon-location',
                    style:'color:red;'
                })        
           ],       
        );     
     }   
 },