开始时我在真机上测试使用 web-view :src= " ‘/hybrid/html/pages/index/index.html?userInfo=‘+JSON.stringify(userInfo)+‘type=‘+webViewType " @message= " getMessage " /web-view 这种形式传参时没有问题会走 UniAppJS
开始时我在真机上测试使用
<web-view :src="‘/hybrid/html/pages/index/index.html?userInfo=‘+JSON.stringify(userInfo)+‘&type=‘+webViewType" @message="getMessage"></web-view>
这种形式传参时没有问题会走UniAppJSBridgeReady 回调但是,离线打包生成app资源在xcode上运行到手机出现不回调
因为官方的demo实例中没有出现问题,因为里面没有向webview传参
后来发现是传参问题,不能用下面形式
<web-view :src="‘/hybrid/html/pages/index/index.html?userInfo=‘+JSON.stringify(userInfo)+‘&type=‘+webViewType" @message="getMessage"></web-view>
我改后的
<template>
<view>
<!-- <web-view :src="‘/hybrid/html/pages/index/index.html?userInfo=‘+JSON.stringify(userInfo)+‘&type=‘+webViewType" @message="getMessage"></web-view> -->
<web-view :src="url" @message="getMessage"></web-view>
</view>
</template>
<script>
//非父子组件传值
import bus from ‘../../static/js/bus.js‘;
import { mapState, mapMutations } from ‘vuex‘;
export default {
computed: mapState([‘userInfo‘, ‘api‘,‘webViewType‘]),
data() {
return {
url:‘‘,
fileList:[]
}
},
onLoad(option) {
console.log(this.webViewType)
this.url=`/hybrid/html/pages/index/index.html?type=${this.webViewType}&token=${this.userInfo.token}`
},
methods: {
getMessage(event) {
this.fileList=event.detail.data[0].fileList
bus.$emit(‘fileList‘,this.fileList)
}
}
}
</script>
<style>
</style>
就可以触发了
