web-view-local.uvue 1.1 KB
Newer Older
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
1
<template>
H
hdx 已提交
2
  <web-view ref="web-view" class="web-view" src="/hybrid/html/local.html" @message="message" @error="error"
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
3
    @loading="loading" @load="load">
H
hdx 已提交
4
  </web-view>
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
5 6 7
</template>

<script>
8 9 10
  export default {
    data() {
      return {
11 12
        loadError: false,
        loadFinish: false
13 14 15
      }
    },
    methods: {
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
16 17
      message(event : UniWebViewMessageEvent) {
        console.log(JSON.stringify(event));
lizhongyi_'s avatar
lizhongyi_ 已提交
18 19 20 21
        let contentStr = JSON.stringify(event.detail);
        <!-- #ifdef APP-IOS -->
          contentStr = JSON.stringify(event.detail.data[0]);
        <!-- #endif -->
W
微调  
wanganxp 已提交
22
        uni.showModal({
lizhongyi_'s avatar
lizhongyi_ 已提交
23
          content: contentStr,
W
微调  
wanganxp 已提交
24 25
          showCancel: false
        });
26
      },
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
27
      error(event : UniWebViewErrorEvent) {
shutao-dc's avatar
shutao-dc 已提交
28
        this.loadError = true
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
29
        console.log(JSON.stringify(event));
30
      },
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
31 32
      loading(event : UniWebViewLoadingEvent) {
        console.log(JSON.stringify(event));
33
      },
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
34
      load(event : UniWebViewLoadEvent) {
35
        this.loadFinish = true;
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
36
        console.log(JSON.stringify(event));
37 38 39
      }
    }
  }
DCloud-yinjiacheng's avatar
DCloud-yinjiacheng 已提交
40 41 42
</script>

<style>
H
hdx 已提交
43 44 45
.web-view {
  flex: 1;
}
W
微调  
wanganxp 已提交
46
</style>