I'm trying to split my barba views into different modules with module.exports.
This is the code i have for the 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;
And this is how i am creating the module
var homeView = new HomeView();
The error i keep getting is 'i is not a constructor'. I do this the same way with backbone views and this works.
I believe you should not do var homeView = new HomeView();
, instead import the module and do HomeView.init();
. These barba.js
view's doesn't look like constructor functions that you manually initialize, they seem to find elements with matching namespace like
<div class="barba-container" data-namespace="homepage">
and create instances internally. Follow the documentation, it doesn't tell you to do var homeView = new HomeView();
我仅通过导入模块(而不创建新实例)进行拆分,并且可以正常工作:
import HomeView from './your/path/HomeView'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.