recently I learned to use axios, to use Douban"s api, in vue-cli. I set axios"s baseurl to Douban"s api. After I set it, there was a cross-domain problem
// main.js
axios.defaults.baseURL = "http://api.douban.com/v2/";
Vue.prototype.$axios = axios;
then I will search the Internet and modify
in config/index.js.proxyTable: {
"/api": {
target: "http://api.douban.com/v2", //
// secure: false, // https
changeOrigin: true, //
pathRewrite: {
"^/api": ""
}
}
},
then request
in the component
this.$axios.get("api/movie/top250",{
})
.then(res=>{
console.log(res);
console.log("ok");
})
.catch(err=>{
console.log(err);
});
found that it can be requested, but will report problems and Error: Network Error, certainly will not log ok, and then I can comment out the baseurl and return the ok without error. Later, I changed baseurl to axios.defaults.baseURL = "https://api.github.com/"
and got the data of github, no problem, but the previous Douban did not work, then the problem arises, how should I cross-domain when I set up baseurl (such as github). When I write Douban"s address directly when I request, I can get it, but still report an error
, that is, how can a request not be affected by baseurl? Please let me know. Thank you.