app-nvue webview加载本地网页,url不能携带参数(如:/hybrid/html/index.html?id=1 改为 /hybrid/html/index.html)。
数据传递使用webview通信。
webview官网:https://uniapp.dcloud.net.cn/component/web-view.html
<template>
<view>
<web-view ref="webview" class="webview" @onPostMessage="handlePostMessage"></web-view>
<button class="button" @click="evalJs">evalJs(改变webview背景颜色)</button>
</view>
</template>
<script>
export default {
data: {
},
methods: {
// webview向外部发送消息
handlePostMessage: function(data) {
console.log("接收到消息:" JSON.stringify(data.detail));
},
// 调用 webview 内部逻辑和方法(方法挂载到window对象上)
evalJs: function() {
this.$refs.webview.evalJs(`方法名(${paramStr})`);
}
}
}
</script>
0 个评论
要回复文章请先登录或注册