使用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/