Vue.js插件错误:未定义
我试图使用一个插件从,如前所述,但我得到一个错误Vue.js插件错误:未定义,vue.js,Vue.js,我试图使用一个插件从,如前所述,但我得到一个错误 this.$dialog.confirm('Please confirm to continue') Uncaught TypeError: Cannot read property 'confirm' of undefined 所以这个$plugin是未定义的。。。。为什么? // I installed it via npm npm install vuejs-dialog main.js 然后我尝试在我的App.vue中使用它
this.$dialog.confirm('Please confirm to continue')
Uncaught TypeError: Cannot read property 'confirm' of undefined
所以这个$plugin是未定义的。。。。为什么?
// I installed it via npm
npm install vuejs-dialog
main.js
然后我尝试在我的App.vue中使用它,单击方法:
App.vue
这是Vue应用程序的常见障碍- 您可以在中找到以下内容: 不要在选项属性或回调上使用箭头函数,例如 创建:=>console.logthis.a或vm.$watch'a',newValue=> 这是我的方法 因为箭头函数绑定到父函数 在上下文中,这通常不是您所期望的Vue实例 导致错误,例如未捕获的TypeError:无法读取属性 未定义或未捕获的类型错误:this.myMethod不是函数 尝试改用普通函数:
methods: {
clicked: function (event) {
event.preventDefault()
console.log('clicked!'). // got it in console
this.$dialog.confirm('Please confirm to continue') // !ERROR
.then(function () {
console.log('Clicked on proceed')
})
.catch(function () {
console.log('Clicked on cancel')
})
}
}
这是Vue应用程序的常见障碍- 您可以在中找到以下内容: 不要在选项属性或回调上使用箭头函数,例如 创建:=>console.logthis.a或vm.$watch'a',newValue=> 这是我的方法 因为箭头函数绑定到父函数 在上下文中,这通常不是您所期望的Vue实例 导致错误,例如未捕获的TypeError:无法读取属性 未定义或未捕获的类型错误:this.myMethod不是函数 尝试改用普通函数:
methods: {
clicked: function (event) {
event.preventDefault()
console.log('clicked!'). // got it in console
this.$dialog.confirm('Please confirm to continue') // !ERROR
.then(function () {
console.log('Clicked on proceed')
})
.catch(function () {
console.log('Clicked on cancel')
})
}
}
应该使用:Vue.prototype,而不是这个
Vue.prototype.$dialog.confirm('Please confirm to continue')
应该使用:Vue.prototype,而不是这个
Vue.prototype.$dialog.confirm('Please confirm to continue')
您没有在最后一个代码中导入VuejsDialog可能的副本它是否在package.json中定义为依赖项?您没有在最后一个代码中导入VuejsDialog可能的副本它是否在package.json中定义为依赖项?方法:{clicked:async function event{event.preventDefault;}方法:{单击:异步函数事件{event.preventDefault;}