小程序代码
<template>
<view class="">
<view class="" v-if="message!=''">{{message}}</view>
<web-view v-else ref="myWebview" :src="graphVisUrl" @load="webLoad" @message="getMessage" @onPostMessage="getMessage"></web-view>
</view>
</template>
<script>
export default {
data() {
return {
courseId:'',
graphVisUrl:'',
message:''
}
},
onLoad(option) {
this.courseId=option.courseId
this.graphVisUrl=`https://zxzcs.intelveh.com/graphvis/index.html?courseId=${this.courseId}`
console.log(this.graphVisUrl,'this.graphVisUrl');
},
methods: {
webLoad(){
// console.log(this.$refs.myWebview,"this.$refs.myWebview");
// setTimeout(()=>{
// this.$refs.myWebview.evalJS(`window.handleData(${JSON.stringify(this.graphVisUrl)});`);
// },500)
},
getMessage(e){
console.log(e,'getMessage');
this.message=JSON.stringify(e)
}
}
}
</script>
<style>
</style>
1 个回复
DCloud_UNI_yuhe
用官网的示例代码试试呢? https://uniapp.dcloud.net.cn/component/web-view.html#getenv