gpt4 book ai didi

javascript - 如何与 Barba 一起使用 module.exports

转载 作者:行者123 更新时间:2023-11-28 04:18:29 26 4
gpt4 key购买 nike

我正在尝试使用 module.exports 将我的 barba View 拆分为不同的模块。

这是我的 View 代码。

var Barba = require('barba.js');

var HomeView = Barba.BaseView.extend({
namespace: 'homepage',

onEnter: function() {

console.log('intro start home');
// The new Container is ready and attached to the DOM.
},
onEnterCompleted: function() {
// The Transition has just finished.
console.log('intro finished home');
},
onLeave: function() {
// A new Transition toward a new page has just started.
console.log('outro start home');
},
onLeaveCompleted: function() {
// The Container has just been removed from the DOM.
console.log('outro finished home');

}
});

HomeView.init();

module.exports = HomeView;

这就是我创建模块的方式

var homeView = new HomeView();

我不断收到的错误是“我不是构造函数”。我用同样的方式处理主干 View ,这很有效。

最佳答案

我相信您不应该执行var homeView = new HomeView();,而是导入模块并执行HomeView.init();。这些 barba.js View 看起来不像您手动初始化的构造函数,它们似乎会找到具有匹配命名空间的元素,例如

<div class="barba-container" data-namespace="homepage">

并在内部创建实例。请遵循文档,它不会告诉您执行 var homeView = new HomeView();

关于javascript - 如何与 Barba 一起使用 module.exports,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45637982/

26 4 0
文章推荐: javascript - 如何在嵌入的 YouTube 视频播放完毕后取消隐藏
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com