(一) 使用 axios vue-axios qsvue
1.qs是必不可少的插件ios
npm install --save axios vue-axios qs
npm
2.安裝完成後,在main.js插入如下代碼axios
//載入axios
import Qs from 'qs'
import axios from 'axios'
import VueAxios from 'vue-axios'
var axios_instance = axios.create({
baseURL:'http://localhost', //自行修改url
transformRequest: [function (data) {
data = Qs.stringify(data);
return data;
}],
headers:{'Content-Type':'application/x-www-form-urlencoded'}
})
Vue.use(VueAxios, axios_instance)api
3.在vue模塊中能夠這樣使用app
this.$http.post('url', {
id:1
}).then(response => {
console.log(response)
}).catch( error => {
console.log(error);
});post
(二)this
1.安裝axiosurl