支付寶是接收form表單提交數(shù)據(jù),所以在vue使用UI的情況下,只能自己模擬創(chuàng)建一個form表單提交數(shù)據(jù)給后臺。
let formData = new FormData()
formData.append("accountId", this.userId)
formData.append("internetTacticsId", this.internetTacticsId)
formData.append("money", this.money)
formData.append("paytype", this.paytype)
let?config?= {
????headers:?{
????????'Content-Type':?'multipart/form-data'
??? }
}? //這個為請求的頭部,以免后臺無法處理當前的媒體格式
this.postAxios('/pay.do?',?formData,?config)
.then(res?=>?{
????document.querySelector('body').innerHTML?=?res? //查找到當前頁面的body,將后臺返回的form替換掉他的內(nèi)容
????document.forms[0].submit()? //執(zhí)行submit表單提交,讓頁面重定向,跳轉到支付寶頁面
})
.catch(function(error) {
????console.log(error)
})