Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js插件错误:未定义_Vue.js - Fatal编程技术网

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;}