element UI - this.$confirm is not a function, this.$message is not a function, this.$alert is not a

在utils下新建loginout.js,引用element MessageBox 弹框后报错,this.$confirm is not a function, this.$message is not a function, this.$alert is not a function。。。

解决:

loginout.js里引用

import { MessageBox } from 'element-ui'

MessageBox.confirm('这是一段内容', '提示', {  
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
}).then(() => {
            。。。。。
})

灵感来自:elementUI——MessageBox组件源码分析 - 简书

  Vue.prototype.$msgbox = MessageBox;
  Vue.prototype.$alert = MessageBox.alert;
  Vue.prototype.$confirm = MessageBox.confirm;
  Vue.prototype.$prompt = MessageBox.prompt;