element-getnativeview.uvue 2.7 KB
Newer Older
shutao-dc's avatar
shutao-dc 已提交
1 2 3 4 5
<template>
  <view id="view" style="flex: 1;">
    <input id="input" value="input" class="input" />
    <textarea id="textarea" value="textarea" class="textarea" />
    <web-view id="webview" src="/hybrid/html/local.html" class="web-view"></web-view>
6 7 8 9
    <button class="button" type="primary" @click="checkViewNativeView">检测view标签原生View</button>
    <button class="button" type="primary" @click="checkInputNativeView">检测input标签原生View</button>
    <button class="button" type="primary" @click="checkTextareaNativeView">检测textarea标签原生View</button>
    <button class="button" type="primary" @click="checkWebViewNativeView">检测webview标签原生View</button>
shutao-dc's avatar
shutao-dc 已提交
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
  </view>
</template>

<script>
  import { checkWebViewNativeView, checkInputNativeView, checkTextareaNativeView, checkViewNativeView } from '@/uni_modules/uts-get-native-view';
  export default {
    data() {
      return {

      }
    },
    methods: {
      checkViewNativeView() : boolean {
        if (checkViewNativeView("view")) {
          uni.showToast({
            title: "检测view原生View成功"
          })
          return true
        }
        console.log("检测view原生View失败")
        return false
      },
      checkInputNativeView() : boolean {
        if (checkInputNativeView("input")) {
          uni.showToast({
            title: "检测input原生View成功"
          })
          return true
        }
        console.log("检测input原生View失败")
        return false
      },
      checkTextareaNativeView() : boolean {
        if (checkTextareaNativeView("textarea")) {
          uni.showToast({
            title: "检测textarea原生View成功"
          })
          return true
        }
        console.log("检测textarea原生View失败")
        return false
      },
      checkWebViewNativeView() : boolean {
        if (checkWebViewNativeView("webview")) {
          uni.showToast({
            title: "检测webview原生View成功"
          })
          return true
        }
        console.log("检测webview原生View失败")
        return false
      }
    }
  }
</script>

<style>
  .input {
    width: 300px;
    height: 40px;
    border-radius: 4px;
    border-width: 1px;
    border-color: black;
    border-style: solid;
    margin: 20px auto;
  }

  .textarea {
    width: 300px;
    height: 80px;
    border-radius: 4px;
    border-width: 1px;
    border-color: black;
    border-style: solid;
    margin: 20px auto;
  }

  .web-view {
    width: 300px;
    height: 120px;
    margin: 20px auto;
    border-radius: 4px;
    border-width: 1px;
    border-color: black;
    border-style: solid;
95 96 97 98
  }

  .button {
    margin: 10px 20px;
shutao-dc's avatar
shutao-dc 已提交
99 100
  }
</style>