laravel 获取javascript文件的Laravel“公共”路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16539900/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Laravel 'public' path for javascript file
提问by dan2k3k4
I'm unsure how I can get something equivalent to: path('public') to work in a Javascript file?
我不确定如何获得相当于:path('public') 在 Javascript 文件中工作的东西?
I basically just need the path to the public folder for displaying some images from my JS file.
我基本上只需要公共文件夹的路径来显示我的 JS 文件中的一些图像。
回答by Jason Lewis
You could opt to create a variable in JavaScripts global namespace in the head of your document and use PHP to echo out the public path.
您可以选择在文档头部的 JavaScript 全局命名空间中创建一个变量,并使用 PHP 来回显公共路径。
<head>
<script>
var public_path = '{{ path('public') }}';
</script>
...