admin管理员组文章数量:1290991
I made a SPA with laravel + vuejs3 (inertia).
My SPA works without worries, but I made a module that is on several sites (WP) which is a js file that loads on a tag with the id="form"
.
It works well on the several sites but here since I use a SPA I have the impression that it does not work.
As soon as I navigate elsewhere with a <Link>
from inertia (so in SPA without refreshing the browser) and I come back to the form it does not work. So it only works the first time, do you have any idea what to do? Because currently I am going through a complete PHP page but I do not like it if I would like to find a solution!
so in my controller I simply have:
return Inertia::render('Form');
and at this point in my view I simply do:
<div id="form"></div>
and in my app.blade.php
<script type="module" crossorigin src="{{ asset('/js/index-8AJeVKiN.js') }}"></script>
when I do that the module does not load, so I did this in the .vue file:
mounted(){
this.loadScript('/js/index-8AJeVKiN.js', () => {
});
},
watch:{
},
methods:{
loadScript(src, callback) {
if (!document.querySelector(`script[src="${src}"]`)) {
const script = document.createElement('script');
script.src = src;
script.type = 'module'; // Ajoute type="module" si nécessaire
script.onload = callback; // Appeler la fonction callback une fois chargé
document.head.appendChild(script);
} else {
callback(); // Appeler la fonction directement si déjà chargé
}
},
},
本文标签: javascriptHow to load a vuejs build into another vuejsStack Overflow
版权声明:本文标题:javascript - How to load a vuejs build into another vuejs? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741521326a2383202.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论