简体   繁体   English

Vue app.js 与主页上的其他 JavaScript 文件发生冲突(Laravel)

[英]Vue app.js colliding with other JavaScript files on homepage (Laravel)

I included Vuejs in my existing project but now it is affecting my original theme JavaScript files.我在现有项目中包含了 Vuejs,但现在它影响了我原来的主题 JavaScript 文件。 Without app.js on my homepage, everything works fine.我的主页上没有 app.js,一切正常。 But when I include it, All UI effects and functionalities on my original theme js file including sliders, canvas, carousels, and dropdowns all stops working.但是当我包含它时,我原始主题 js 文件上的所有 UI 效果和功能,包括滑块、canvas、轮播和下拉菜单都停止工作。

How do I stop Vue from colliding with my theme js and causing it to break如何阻止 Vue 与我的主题 js 发生冲突并导致其中断

regarding CSS collisions...关于 CSS 碰撞...

You can solve by making sure all your css is getting scoped.您可以通过确保所有 css 都得到范围来解决。

instead of代替

<style>
/* global styles */
</style>

use利用

<style scoped>
/* local styles */
</style>

Vue will then compile your css to have generated is like h1[data-v-f3f3eg9] that will prevent other elements on the page from being formatted by your vue code.然后,Vue 将编译您的 css 以生成类似于h1[data-v-f3f3eg9]内容,这将防止页面上的其他元素被您的 vue 代码格式化。 It will not, however, prevent your page code from affecting the vue components unless you add css resets to you components.但是,除非您将 css 重置添加到您的组件,否则它不会阻止您的页面代码影响 vue 组件。

regarding JS code...关于JS代码...

it's hard to tell without seeing what the collisions are.如果不看到碰撞是什么就很难说清楚。 AFAIK There's no magical setting for that. AFAIK 没有什么神奇的设置。

I found the solution for this collision我找到了这次碰撞的解决方案

Put your app.js at the top of your script links like:将您的app.js放在脚本链接的顶部,例如:

<script src="{{ asset('js/app.js') }}"></script>

Then然后

<script> $.noConflict(); /script>

After that put your other JavaScript it will work fine.之后放上你的其他 JavaScript 它会正常工作。

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

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