Javascript VueJS错误“;未捕获类型错误:this.sendDrag不是函数;装入()

Javascript VueJS错误“;未捕获类型错误:this.sendDrag不是函数;装入(),javascript,vue.js,vuejs2,Javascript,Vue.js,Vuejs2,我不明白为什么this.sendDrag('started')返回此错误: “未捕获的TypeError:this.sendDrag不是函数” 什么原因导致错误以及如何修复错误?您需要在闭包中捕获this的值,因为您是从具有不同this的函数调用它的 如果您使用箭头lambda表示法()=>{}而不是函数(),它将自动为您捕获此。这就是这两种符号之间的真正区别 mounted () { this.$nextTick(() => { const that

我不明白为什么
this.sendDrag('started')
返回此错误:

“未捕获的TypeError:this.sendDrag不是函数”


什么原因导致错误以及如何修复错误?

您需要在闭包中捕获
this
的值,因为您是从具有不同
this
的函数调用它的

如果您使用箭头lambda表示法
()=>{}
而不是
函数()
,它将自动为您捕获
。这就是这两种符号之间的真正区别

mounted () {
        this.$nextTick(() => {
          const that = this;
          this.$refs.flickity.on('dragStart', function () {
            that.stageDragging = true
            that.sendDrag('started')
          })


我认为这是因为这个范围。你可以使用箭头功能。。。或使用自助服务。我的意思是箭头函数而不是函数()我不明白你的意思。您能举个例子吗?以下是您问题的解决方案:
mounted () {
        this.$nextTick(() => {
          const that = this;
          this.$refs.flickity.on('dragStart', function () {
            that.stageDragging = true
            that.sendDrag('started')
          })