Work before the time used Vue development, but the scaffolding is the eldest to provide, they have not actually set up, recently have time, they walked the whole process, to axios here or encountered some problems, summed up, good memory as bad pen, this is not false
1. After installing Axios, introduce in Main.js: (this. $axios can be used in the assembly)
Import Axios from ' Axios ';
Vue.prototype. $axios = Axios;
2. Direct use, encountered a cross-domain problem, the console error will probably have access-control-allow-origin such as red words, find config/index.js,p configuration dev proxytable :
Dev: {
//Paths
proxytable: {
'/api ': {
target' http://***:8080/',
changeorigintrue,
pathrewrite: {
' ^/api '///Here replaces the address in target with '/api ', calls ' Http://***:8080/user/add ', can be written '/api/user/add '
}
}
}
3. Then start testing correctly:
1. $axios. Get ('/api/huodonglist '). Then (res => console. Log (res));
2) this. $axios. Post ('/api/list ', params). Then (res => console. Log (res));
Params is like this: (in order to ensure that the transmission to the backend is the key value of the Key:value form); Here, the method should have other, Vue QS module, specific usage have time to see
Urlsearchparams ();
Params.append (' json'123 ');(' 123 ' is the value you want to transmit to your descendants.