var Main = { methods: { open4() { //1.我們要將后台返回的數據轉存成數組,格式為: data=['錯誤提示一!!!','錯誤提示二!!!','錯誤提示三!!!']; let data = ['錯誤提示一!!!','錯誤提示二!!!','錯誤提示三!!!']; //2.新建newDatas數組 let newDatas = []; const h = this.$createElement; //3.通過循環data數組,調用h方法,將每項值傳給h,h('標簽名',樣式,具體內容) for(let i in data){ //4.將data數據push進newDatas數組中 newDatas.push(h('p',null,data[i])); }; this.$msgbox({ title: '消息', //5.將newDatas傳進h方法生成的代碼格式為: // <div> // <p>錯誤提示一!!!</p> // <p>錯誤提示二!!!</p> // <p>錯誤提示三!!!</p> // </div> message: h('div',null, newDatas), showCancelButton: true, confirmButtonText: '確定', cancelButtonText: '取消', }).then(action => { this.$message({ type: 'info', message: 'action: ' + action }); }); }, } } var Ctor = Vue.extend(Main) new Ctor().$mount('#app')
