參考地址https://www.kancloud.cn/yunye/axios/234845肿孵、
npm install axios
安裝axios在項目中
在main.js配置內(nèi)容
import axios from 'axios'
Vue.prototype.$axios = axios
配置qs解碼(post)
import qs from 'qs'
Vue.prototype.$qs = qs
使用:
url路徑
method傳值方式post弟孟、get
params傳值參數(shù)
.then 里是后臺返回結(jié)果
?.catch里是網(wǎng)絡錯誤或后臺服務器出bug等等
第一種
created(){
??????????????????????????? this.$axios({
???????????????????????????????????? url:'https://dawn.changxvan.top/api/Order/order_details',
???????????????????????????????????? params:{
?????????????????????????????????????????????? //id:274696
?????????????????????????????????????????????? id:2,
?????????????????????????????????????????????? order_id:3
???????????????????????????????????? }
??????????????????????????? }).then((s)=>{
???????????????????????????????????? console.log(s.data)
???????????????????????????????????? }).catch((e)=>{
?????????????????????????????????????????????? console.log(e)
???????????????????????????????????? })
?????????????????? },
第二種
created(){
??????????????????????????? this.axios({
???????????????????????????????????? url:'https://dawn.changxvan.top/api/Order/order_details',
???????????????????????????????????? params:{
?????????????????????????????????????????????? //id:274696
?????????????????????????????????????????????? id:2,
?????????????????????????????????????????????? order_id:3
???????????????????????????????????? }
??????????????????????????? }).then(function(rel){
???????????????????????????????????? console.log(rel)
??????????????????????????? }).catch(function(err){
???????????????????????????????????? console.log(err)
??????????????????????????? })
?????????????????? },