这是饿了么官方给的例子:
this.$alert('这是一段内容', '标题名称', {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info',
message: `action: ${ action }`
});
}
});
}
代码量太多,于是我想自己封装一个:
import { Message } from 'element-ui'
export function alertOK(msg,title){
this.$alert(msg, title, {
confirmButtonText: '确定',
callback: action => {
this.$message({
type: 'info'
});
}
});
}
export default {alertOK}
设为全局,main.js:
import common from '@/common/global.js'
Vue.prototype.$common = common
调用时报错:
submit:function(){
this.$common.alertOK("删除成功","提示");
}
你的
this
指向不对呗,执行this.$common.alertOK
时上面的this
指向common
。改成