天天看點

vue-axios中post和get攜帶參數和token

get請求攜帶id删除某一項

this.KaTeX parse error: Expected '}', got 'EOF' at end of input: …igns/delete?id={id}`,        //利用了字元串模闆來攜帶id

headers:{

‘token’:window.localStorage.getItem(‘token’)    //由于是多頁面應用是以token存儲在本地localStorage中

}

},

).then(res=>{

console.log(res)

this.inlist()

}).catch(req=>{

console.log(req)

})

this.$axios.get(url,{

  headers:{

  token:******,

},

params:{    //攜帶的資料

     param1: string,

     param2: string

}

}).then(res=>{})

.catch(req=>{})

post請求

this.$axios.post(’/scihua/webapp/userorder/preCreateOrder’,{

“count”: this.count, //數目 預設1

“fileSelectKey”: this.fileSelectKey, //選擇下載下傳檔案的規格 格式_dpi

“fileType”: this.fileType, //下載下傳的檔案類用到的格式屬性

“height”: this.height, //高度

“orderSn”: this.geturl(‘orderSn’), //訂單id

“orderType”: “prodFile”, //訂單類型

“payType”: “wxpay”, //支付方式 alipay wxpay

“resolution”: this.resolution, //下載下傳的檔案類用到的分辨率

“width”: this.width //寬度

},{

headers:{

‘token’:window.localStorage.getItem(‘token’)    //也是在本地中拿到token

}

}).then(res=>{

console.log(res)

if (res.data.code500){

this.msg=res.data.msg                //背景傳回code500時候我們将錯誤回饋到頁面上

this.ish1=true

}else {

this.isshow=true

this.value=res.data.code_url

}

}).catch(req=>{

console.log(req)

this.ish1=true

})

另外一種請求方式就是

data:{            //在data中建立對象,然後我們post請求中攜帶過去

wx:{

openid:null,

headimgurl:null,

nickname:null,

unionid:null,

phone:null,

password:null

}

}

this.$axios.post(’/scihua/webapp/login/bindingExistUser’,this.wx)

.then( res=> {

if(res.data.msg == ‘success’){

window.localStorage.setItem('token',res.data.token)
    setTimeout(()=>{
    window.location.href='file.html'
    },300)
}else{

    this.warning(res.data.msg)
}
           

}).catch( req=> {

console.log(req)

})

繼續閱讀