1 Axios.get('URL', {params: this.getParams}).then((res) => { 2 // url: 请求的接口地址 3 // params: 参数 4 this.modelOne = res.data.results.list 5 this.pageInfo1 = res.data.results.pageInfo 6 }, (err) => { 7 this.$Message.error(err) 8 })
1 Axios({ 2 method: 'POST', 3 url: URL, 4 data: Data 5 }).then((res) => { 6 console.log(res) 7 }, (err) => { 8 console.log(err) 9 })
自选配置项:(不知道为啥,整个对象赋给axios.defaults失败了,只好用这种笨方法)
1 axiosCon: function () { 2 axios.defaults.baseURL = this.HOST 3 axios.defaults.timeout = 10000 4 axios.defaults.responseType = 'json' 5 axios.defaults.xsrfCookieName = '111' 6 axios.defaults.xsrfHeaderName = 'demo' 7 axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded' 8 }