after groping for a few days, I basically know how to use it, and I throw a brick to attract jade here.
configure ajaxUrl, prefix address
const ajaxUrl = env === 'development' ?
'http://192.168.1.230:8080/nis-service/' ://
env === 'production' ?
'https://www.url.com' ://
'https://debug.url.com';//debug
ternary selector, configured in build/env.js
export default "development";//developmentproduction
configure parameters in util.ajax
util.ajax = axios.create({
baseURL: ajaxUrl,//
timeout: 30000,//
headers: {//
"Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
}
});
introduce qs into the util.js file
import qs from 'qs';
create your own method in util.js, take post as an example
util.post = function (url, data) {
return util.ajax({
url,//
method: 'post',//
data:qs.stringify(data,{ arrayFormat: "repeat" })//qs
})
.then(response => {//
console.log(response);
return response;
})
.catch(error => {//
console.log(error);
return error;
});
}
introduce util.js in the components you need to use.
import util from "../../../libs/util.js";
just use it directly
util.post("url",{
key;value
})
.then(response => {
})
.catch(error => {
});
if you have a better package or use, please do not hesitate to give us your advice, and please pat the passing god.
good, learn