我們平時遇到的提示信息都是一行展示的,但是最近的項目要求將不符合要求的數據全部換行展示。樣式如下:
頂部提示信息message
代碼實現如下:
let returnMsgList = [ ”用戶’孫小小'的登錄手機號:138已占用,請修改“, ”用戶’孫xx'的登錄手機號:138已占用,請修改“ ]; // 最終展示數據 , 創建元素; let newDatas = [],h = this.$createElement; // 循環數據 依次放入最終數據中 for (const i in returnMsgList) { newDatas.push(h('p', null, returnMsgList[i])) } // 彈出優雅展示 this.$message.error({ message: h('div', null, newDatas) });
同理:confirm 提示信息
代碼實現如下:
let returnMsgList = [ ”用戶’孫小小'的登錄手機號:138已占用,請修改“, ”用戶’孫xx'的登錄手機號:138已占用,請修改“ ]; let newDatas = [],h = this.$createElement; for (const i in returnMsgList) { newDatas.push(h('p', null, returnMsgList[i])) } _this.$confirm( h('div', null, newDatas), '提示', { confirmButtonText: '確定', cancelButtonText: '取消', type: 'warning' }).then(() => { this.$message({ type: 'success', message: '已導入' }); }).catch(() => { this.$message({ type: 'info', message: '已取消導入' }); });
代碼實現環境:vue+elementUI。