laravel动态生成js文件


应为我要做SPA web。所以需要动态的配置文件
比如我要:xxx.com/setter.js
我路由是这样写的

Route::get('/setter.js', 'xxx@setter');

控制器里面就是是这样的

public function setter()
{
    return response()->view('setter',[],200)->header('Content-Type','application/javascript');
}

我的视图文件setter.blade.php是这样写的
我需要用到csrf_token,不然我直接静态了。

(function(root,factroy){
    typeof root.xxxx === 'object' ? xxxx.setter = factroy() :
    root.setter = factroy();
}(this,function(){
    return {
        name:'xxx',
        csrf:'{{ csrf_token() }}'
    };
}));

放在script的src里面返回的是404,没有内容。
放在link:css的href里面返回404,没有内容。
放在img的src里面返回404,有内容。
地址栏访问返回404,有内容。

我真的醉了。


点赞 取消点赞 收藏 取消收藏

<< 上一篇: Unable to detect application namespace.

>> 下一篇: 资源路由的show方法 如何使用