vue端:
<template>
<view>
<web-view ref="webview" src="/hybrid/html/test.html"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
onLoad: function(option) {
this.openWebViewPopup()
},
methods: {
openWebViewPopup() {
console.log("webview----1>")
setTimeout(() => {
let data = {"a":1}
console.log("webview---2>")
const webview = this.$scope.$getAppWebview();
webview.evalJS(`receiveData('${JSON.stringify(data)}')`);
}, 3500);
},
}
}
</script>
h5端:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport"
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
</head>
<body>
<h1>测试html</h1>
</body>
</html>
<script>
window.receiveData = (data) => {
console.log('Received from UniApp:', data);
};
</script>
0 个回复