目的: 封装一个 myMessage 函数,可以传数组和字符串内容进去
import { ElMessageBox, ElMessage } from 'element-plus'
// 目的: 改造封装一个 myMessage 函数,可以传数组和字符串内容进去
export function myMessage2(str,title) {
var newArr
const h = this.$createElement; // 这里写错了
if (Array.isArray(str)){ // 如果str传进来是数组,就遍历
newArr =[]
for(let i =0; i < str.length; i++){
newArr.push(h('h2', null, str[i]))
}
}else{
newArr = h('span', null , str)
}
ElMessageBox({
title: title,
message: h('h1', null, newArr),
showCancelButton: false,
confirmButtonText: 'OK',
})
}