vue-cli3.0 axios跨域請求代理配置及埠修改
阿新 • • 發佈:2018-12-16
1.安裝 axios
vue add axios
2.專案根目錄下新建 vue.config.js
// vue.config.js module.exports = { devServer: { port: 埠號, proxy: { '/apis': { target: 'https://movie.douban.com/', // target host ws: true, // proxy websockets changeOrigin: true, // needed for virtual hosted sites pathRewrite: { '^/apis': '' // rewrite path } }, } } };
3. 重啟服務npm run serve
4. *.vue 檔案中請求例項
this.axios.get('/apis/ithil_j/activity/movie_annual2017').then(res => {
console.log(res.data)
}, res => {
console.info('呼叫失敗');
})