關注公眾號【Miles】查看更多技術文檔
1、確認接口返回值 賦給 this.$router.replace({path: '/aliPay', query: {data: resp.data.data.data}}); 跳轉aliPay支付頁面
/ /確認支付
Pay(){
toPay({ }).then( resp =>{
if (resp.data.code == 0) {
this.$router.replace({path: '/aliPay', query: {data: resp.data.data.data}});
}
})
}
2、喚起支付寶頁面 單獨頁面 aliPay(index.vue)
<template>
<div v-html="html"></div>
</template>
<script>
export default {
data() {
return {
html: ''
}
},
methods: {
fetchVideoPay() {
this.html = this.$route.query.data;
this.$nextTick(() => {
document.forms[0].submit() //渲染支付寶支付頁面
})
}
},
mounted() {
this.fetchVideoPay()
}
}
</script>
3、支付成功后 返回頁面的地址需要后端設置
方案2:
發起支付請求 返回結果直接賦值在下方代碼
document.querySelector('body').innerHTML = resp.data.data //查找到當前頁面的body,將后臺返回的form替換掉他的內容
document.forms[0].submit()