赞
踩
//uniapp页面中
<web-view :src="src" @message="getMessage" @onPostMessage="getPostMessage">
</web-view>
data() {
return {
nowObj:{
name:'' 我是uniapp的值",
},
src:" "
}
},
onLoad() {
this.src = 'http://192.168.28.57:3333/#/signin?itemObj=' + JSON.stringify(this.nowObj)
},
//直接在mounted中获取
JSON.parse(this.$route.query.itemObj) //获取到uniapp传过来的值
methods:{
// 监听返回事件
backChange(){
uni.postMessage({
data: {
action: 'message'
}
})
},
}
<web-view :src="src" :update-title="false" @message="getMessage" @onPostMessage="getPostMessage">
</web-view>
methods: {
getMessage(e) {
console.log('拿到webview传来的值', e);
},
}
destroyed(){ //销毁监听 window.removeEventListener('popstate',this.backChange,false) }, mounted() { if(window.history && window.history.pushState){ history.pushState(null, null, document.URL); window.addEventListener('popstate',this.backChange,false) } }, methods:{ // 监听返回事件并传参 backChange(){ uni.postMessage({ data: { action: 'message' } }) //navigateBack必填,否则关闭不了 uni.navigateBack() }, }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。