vue文件
<template>
<view>
<web-view :src="pdfUrl" @message="handlePostMessage"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
pdfUrl:'',
from:''
}
},
onLoad() {
this.pdfUrl = `/hybrid/html/web/viewer.html?file=../../../static/1.pdf`
},
methods: {
handlePostMessage: function(data) {
console.log(data)
uni.showModal({
title: '测试',
content: '收到信号了',
showCancel: false,
});
}
}
}
html调用
<link rel="resource" type="application/l10n" href="locale/locale.properties">
<script src="locale/unijs.js"></script>
<script src="../build/pdf.js"></script>
<script src="viewer.js"></script>
viewer.js中发送
uni.postMessage({data: {pdfTitle: "测试"}});