vue實現跨域請求,需要在vue.config.js里添加以下設置
proxy: { '/service/rest': { target: 'http://localhost:8080/autotable/service/rest', ws: true, changeOrigin: true, pathRewrite:{ '^/service/rest':'' } } }
其中 ,將changeOrigin設置為true,就不會存在無法跨域請求的問題了。
然后就可以直接在下面引用axios調用了。
import axios from '@/api/api'; export default { userList(params) { return axios.post('service/rest/api/user/logincode', params); }, };