Laravel,在模板中添加javascript到scripts.js文件

我发现如果我有一个模板的特定javascript,我需要用我的整体脚本实际渲染它。 js文件,而不仅仅是该特定模板的片段。 有没有办法在laravel中默认执行此操作? </ p>

所以将模板中的所有javascript附加到编译的scripts.js文件中? 它只会使输出更有吸引力,并确保我有必要的依赖项和对象? </ p>
</ div>

展开原文

原文

I am finding that if I have specific javascript for a template, I need to actually render it with my overall scripts.js file, not just as a snippet on that particular template. Is there any way to do this in laravel by default?

So append all javascript in the template to the scripts.js file that is compiled? It would just make the output a lot more attractive and would ensure that I have the necessary dependencies and objects?

1个回答



如果您使用的是Laravel Mix,可以使用 mix.scripts()。</ p>

  mix.scripts([
'public /js/admin.js',
'public / js / dashboard.js'
','public / js / all.js');
</ code> </ pre>

值得注意的是,Blade提供 @push和@stack 指令。 这允许您控制脚本输出的时间,地点和顺序。</ p>
</ div>

展开原文

原文

If you're using Laravel Mix, you can combine multiple scripts together using mix.scripts().

mix.scripts([
    'public/js/admin.js',
    'public/js/dashboard.js'
], 'public/js/all.js');

Worth noting, Blade offers the @push and @stack directives. This allows you to control when, where and in what order your scripts are output.

dongtu0363
dongtu0363 谢谢didge #thumbsup
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问