
本文共 2662 字,大约阅读时间需要 8 分钟。
Vue ????????
???????????????????????????? Vue ????????????????????????????????????????????????????? Vue ??? vue.config.js
????????
1. ????
?????????????????????????????????????????????????????????????????????????????????????????????
2. Vue ???????
Vue ???????????????????????????????????????????????????????????? 404?????????
3. ?? Vue ???????
??????????????? vue.config.js
???????????????????
????? vue.config.js
??????????????? vue.config.js
????????????????????????
?? devServer ???? vue.config.js
???? devServer
????????
module.exports = { devServer: { open: true, // ????? host: 'localhost', // ?????? port: 8080, // ????? https: false, // ?? HTTPS ?????? proxy: { '/api': { target: 'http://localhost:8888/api/', // ????????????? ws: true, // ?? WebSocket ?? changeOrigin: true, // ???? pathRewrite: { '^/api': '' // ???? /api } }, '/dwp': { target: 'http://localhost:8881/dwp/', // ????????????? ws: true, changeOrigin: true, pathRewrite: { '^/dwp': '' } } } }}
??????/api
? /dwp
???????????????????pathRewrite
????????????????????????????????
??????????????? npm run dev
? yarn dev
?Vue ??????? vue.config.js
?????????? devServer?
????????????? Axios ? native fetch ???????????? /api
? /dwp
???????? URL????
import axios from 'axios';Vue.prototype.$http = axios;// ?const fetch = (url, options) => { return new Promise((resolve, reject) => { fetch(url, options).then(response => { resolve(response); }).catch(error => { reject(error); }); });};
???????????????????????????
4. ??????
??????????????????????????????? vue.config.js
?????????????????
module.exports = { devServer: { open: true, host: 'localhost', port: 8080, https: false, proxy: { '/api': { target: 'http://localhost:8888/api/', ws: true, changeOrigin: true, pathRewrite: { '^/api': '' } }, '/dwp': { target: 'http://localhost:8881/dwp/', ws: true, changeOrigin: true, pathRewrite: { '^/dwp': '' } }, '/admin': { target: 'http://localhost:8882/admin/', ws: true, changeOrigin: true, pathRewrite: { '^/admin': '' } } } }}
???????????????????????????????????
5. ????
??????????????????????????????????
http://localhost:8888
???????/api
?????????????????????????????
pathRewrite
??????????????????????????????????????????????????????????????
6. ??
???? Vue ? vue.config.js
?????????????????????????????????????????????????????????????????????????????????????????????