[feat][V]:引入axios,并新增axios工具函数

master
Romesum 5 years ago
parent 52cb58f5f5
commit 061b10da10

@ -8,6 +8,7 @@
"build": "rimraf dist && webpack -p --progress --hide-modules"
},
"dependencies": {
"axios": "^0.19.2",
"element-ui": "^2.3.4",
"vue": "^2.5.16",
"vue-router": "^3.1.6"

@ -0,0 +1,37 @@
import axios from 'axios'
import config from "~/config";
// http get工具函数 获取数据
export function get(url, params) {
return request(url, 'GET', '',params)
}
export function post(url, data) {
return request(url, 'POST', data,'')
}
async function request(url, method, data, params, header = {}) {
return new Promise((resolve, reject) => {
axios({
data,
params,
method,
header,
url: config.host + url,
success: function (res) {
// 0:正常请求
// -1:错误请求
if (res.data.code === 0) {
resolve(res.data.data)
} else if (res.data.code === -2) {
reject(res.data)
} else {
reject(res.data)
}
},
fail(res) {
console.log(res)
}
})
})
}

@ -55,11 +55,11 @@ module.exports = (options = {}) => ({
extensions: ['.js', '.vue', '.json', '.css']
},
devServer: {
host: '127.0.0.1',
host: '192.168.31.140',
port: 8010,
proxy: {
'/api/': {
target: 'http://127.0.0.1:8080',
target: 'http://192.168.31.140:8080',
changeOrigin: true,
pathRewrite: {
'^/api': ''

Loading…
Cancel
Save