dqrfdl5708
2018-04-08 13:42
浏览 514
已采纳

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

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?

图片转代码服务由CSDN问答提供 功能建议

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

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhong3887 2018-04-08 14:17
    已采纳

    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.

    点赞 打赏 评论

相关推荐 更多相似问题