在使用element ui,采用局部引入时候,报错TypeError: this.$confirm is not a function
。 因为没有在vue的实例上挂载
c
o
n
f
i
r
m
和
confirm和
confirm和message导致的报错
修改element.js文件: 1 引入messageBox 插件
import {MessageBox} from ‘element-ui’
2 在vue 的原型对象上挂载confirm
Vue.prototype.$confirm = MessageBox.confirm
如下图所示: 以后就可以放心的在vue中的任何文件使用this.
c
o
n
f
i
r
m
或
者
t
h
i
s
.
confirm或者this.
confirm或者this.message了。比如:你想用MessageBox中的confirm方法,现在可以这样用:
点击打开 Dialog
这是一段信息
取 消
确 定
export default {
data () {
return {
dialogVisible: false
}
},
methods: {
handleClose (done) {
const _this = this
_this.$confirm('确认关闭?')
.then(_ => {
done()
})
.catch(_ => {
})
}
}
}