一、前端请求的封装
1.将请求地址封装起来,以便日后修改,在src/assets/js目录下创建getPath.js文件
export default function getUrl(str) {
let url = 'http://localhost:8000/' + str;
return url;
}
2.在同一个目录下创建axios.js文件
我的前端数据交互使用的模块使用的是axios
import axios from 'axios'
import getUrl from './getPath'
export default {
Get: (config) => {
axios({
methods: "get",
url: getUrl(config.url),
params: config.params
}).then((res) => {
stateDetection(res);
config.callback && config.callback(res);
})
},
Post: () => {
axios({
methods: "post",
url: getUrl(config.url)
}).then((res) => {
stateDetection(res);
config