简体   繁体   English

使用 Barba.js 和单独的 JS 文件时遇到问题

[英]Having trouble using Barba.js and separate JS files

I've setup Barba.js on my Wordpress website.我已经在我的 Wordpress 网站上设置了 Barba.js。 It seems to be working.它似乎正在工作。 the only thing is that when I transition to other pages, my other JS files don't load until a hard refresh.唯一的问题是,当我转换到其他页面时,我的其他 JS 文件在硬刷新之前不会加载。

I think to solve this, I have to use namespace and BeforeEnter and re-run my separate JS file within that我认为要解决这个问题,我必须使用namespaceBeforeEnter并在其中重新运行我单独的 JS 文件

The only problem is I don't know how to do that.唯一的问题是我不知道该怎么做。 I've looked all over the net.我在网上到处找。

I've tried this (which I know is not right, but maybe on the right track?)我试过这个(我知道这是不对的,但也许在正确的轨道上?)

let script = document.createElement('script');
script.src="/flickity.init.js";   
next.container.appendChild(script);

Any help would be appreciated :)任何帮助,将不胜感激 :)

Thanks in advance!提前致谢!

Was actually a pretty simple fix.实际上是一个非常简单的修复。

I just wrapped my other JS files code in a const runScripts = function () {} then called the function runScripts() inside a view in my custom Barba script with beforeEnter({ next }) {} and a relevant name space.我只是将我的其他 JS 文件代码包装在 const runScripts = function () {}中,然后使用beforeEnter({ next }) {}和相关的名称空间在我的自定义 Barba 脚本的视图中调用函数 runScripts()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM