<template>
  <view class="webview-box">
    <web-view
      v-if="url"
      ref="webview"
      class="webview"
      :src="url"
      @onPostMessage="PostMessage"
      @message="PostMessage"
    ></web-view>
  </view>
</template>  
<script>
export default {
  data() {
    return {
      url: "https://sit-nanhuacs.4dage.com/web/index.html#/home",
      token: uni.getStorageSync('token')
    };
  },
  onLoad(data) {
    console.log("postMessage1: ", data);
      this.url = data.url + "?token=" + this.token;
    console.log("postMessage1: ", this.url);
  },
  methods: {
    // 接收h5页面发来的键值判断需要执行的操作
    PostMessage(evt) {
      console.log("2222postMessage1: ", evt);
    },
    // 获取到对应webview(关键)通过evalJs(注意大小写，如果不知道evalJ是什么，可自行百度) 执行网页的函数，可对其进行传参，完成与网页的通讯
    handlePostMessage(res) {
      console.log("212", res);
    },
  },
};
</script>  

<style>
.webview-box {
  position: absolute;
  left: 0px;
  right: 0px;
  top: 0px;
  bottom: 0px;
}

.webview {
  flex: 1;
  height: 300rpx;
}
</style>
