所以我使用Vue CLI
在webpack-dev-server上使用vue.js localy在我的mac上开发一个站点。我想使用Vue Resource
从我的后端获取数据,该数据托管在虚假VM(local.dev)上。我尝试在config / index.js文件中添加代理,如下所示:
proxyTable: {
'/pf': {
target: 'local.dev/portfolioVue/public',
secure: false,
changeOrigin: true,
pathRewrite: {
'^/pf': ''
}
}
},
然后我在src / App.vue
中安装了这个函数mounted () {
this.$http.get('/pf').then(response => {
console.log('tutu');
}, response => {
console.log('erreur');
})
}
在src / main.js中我添加了:
Vue.http.headers.common['Access-Control-Allow-Origin'] = 'local.dev/portfolioVue/public';
Vue.http.headers.common['Access-Control-Request-Method'] = 'GET';
这是在https://laracasts.com/discuss/channels/vue/cors-and-vuejs?page=1
上找到的但现在我收到了这些错误
Refused to set unsafe header "Access-Control-Request-Method"
XMLHttpRequest cannot load http://local.dev/portfolioVue/public/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9080' is therefore not allowed access.
我试图获得一个返回Json
的php文件(public / index.php)<?php echo json_encode('tutu') ?>
VM配置会出现问题吗?
提前感谢您的帮助
答案 0 :(得分:0)
所以在研究之后,这是一个CORS问题而且实际上有一个谷歌浏览器的插件可以解决这个问题,也可以根据喜好选择firefox的插件。
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi