为什么 Laravel 中间件 CORS 不适用于 Vue.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/54705229/
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
Why did Not working Laravel middleware CORS with Vue.js
提问by banda
working with Laravel 5.7 as backend and Vue.js as frontend. so, I need send http request fron Vue to Laravel backend. so, I used Laravel CORS package to using github link as following https://github.com/barryvdh/laravel-corsbut it is not sucess and (not pass data to table fron vue). and my console error is `Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/api/addItem. (Reason: CORS request did not succeed).
使用 Laravel 5.7 作为后端,使用 Vue.js 作为前端。所以,我需要从 Vue 向 Laravel 后端发送 http 请求。所以,我使用 Laravel CORS 包来使用 github 链接,如下所示https://github.com/barryvdh/laravel-cors但它不成功并且(不将数据传递到表 fron vue)。我的控制台错误是“跨源请求被阻止:同源策略不允许读取http://localhost:8000/api/addItem 上的远程资源。(原因:CORS 请求没有成功)。
how can fix this error?`
如何修复此错误?`
回答by Rejoanul Alam
It is only for localhost & in production if you use https
then this issue will not raise any more. However for local test you can open chrome browser in disabled security mode. Details about how to do
它仅适用于 localhost & 在生产中,如果您使用,https
则此问题将不再出现。但是对于本地测试,您可以在禁用的安全模式下打开 Chrome 浏览器。有关如何操作的详细信息