問題描述:
給公司做微信小程序時遇到了這個問題,用mpvue框架搭建的小程序,從首頁點擊進去,先跳轉到一個中間頁面,在中間頁面放上webview鏈接到外部的H5頁面,這時點擊小程序左上角自帶的返回按鈕,第一次會跳轉到空白頁,再點一次才能跳轉到首頁。
首頁:

詳情頁:

這時需要點擊左上角的返回箭頭兩次,才能跳轉到首頁
解決辦法:
小程序跳到外部頁面方法:
1、從首頁(index)跳轉到中間頁(template):
goPage(id){
wx.navigateTo({url:'../template/main?id='+id})
}
2、template頁面:
<template>
<div>
<web-view :src="aSrcs"></web-view>
</div>
</template>
<script>
export default {
data(){
return{
aSrcs:""
}
}
,
methods: {
aSrc(){
var id = this.$root.$mp.query.id
if(id==1){
return 'https://api.1yunsong.com/Hxjy/Wx/detail_gs'
}
else if(id==2){
return 'https://api.1yunsong.com/Hxjy/Wx/detail_cs'
}
else if(id==3){
return 'https://api.1yunsong.com/Hxjy/Wx/detail_zs'
}
else if(id==4){
return 'https://api.1yunsong.com/Hxjy/Wx/detail_qy'
}
else{
return false
}
}
},
mounted() {
this.aSrcs = this.aSrc()
},
}
</script>
從外部頁面再跳回到微信小程序:(在H5頁面中寫)
1、先引入一個js文件
<script src="https://res.wx.qq.com/open/js/jweixin-1.3.0.js"></script>
2、在script中加入一行代碼
<script>
window.onunload = function(){
wx.miniProgram.navigateBack({})
}
</script>
這樣就可以了!
