javascript - 在 fullPage 和 Vuejs 中绑定(bind)辅助功能

标签 javascript function vue.js

使用VueJS,收到错误app.js:11754Uncaught TypeError: (intermediate value)(intermediate value).bind is not a function。一旦在 fullPage 内触发,我不想调用 isLoaded 函数。我知道我需要绑定(bind)“this”才能使事情正常工作,但是到目前为止它还不起作用。绑定(bind)(this)应该放在哪里?

        one_page: function () {
        $('#dosbcn').fullpage({
            anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],
            afterLoad: function(anchorLink, index){
                //using index
                if(index == 2){
                    console.log('second page here');
                    this.isLoaded(); // Vue function to be called if the index is equal to 2.
                }
            }
        });
    },
    isLoaded: function () {
        console.log('hello world');
    }

最佳答案

为了在函数内部调用 vue 方法,我需要在目标函数外部声明它,如下所示:

        one_page: function () {
        var that = this; // declare this as that here...
        $('#dosbcn').fullpage({
            anchors: ['firstPage', 'secondPage', 'thirdPage', 'fourthPage', 'lastPage'],
            afterLoad: function(anchorLink, index){
                //using index
                if(index == 2){
                    that.isLoaded();
                }
            }
        });
    },
    isLoaded: function () {
        console.log('yep yep')
    }

关于javascript - 在 fullPage 和 Vuejs 中绑定(bind)辅助功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37997360/

相关文章:

javascript - 根据位置标签填充下拉列表

function - 在函数和结构中使用定义的常量而不让它们变空(Swift)

javascript - 我可以将函数名称作为数组变量吗?

vue.js - Swiper Vue 组件事件处理程序在 Nuxt 中不起作用

javascript - 我如何结合谷歌地图和基于主干 View 的信息框

javascript - Angular 数据是 Angular 缓存的依赖项还是反之亦然?

C语言。奇怪的函数行为

typescript - 使用Typescript和类组件装饰器时如何将数组传递给Vue中的 Prop

javascript - 为什么 Vue.js 不打印一个对象属性,即使它存在?

c# - signalR 的客户端特定消息