Dx-zuo / vue-3-webview-js-bridge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vue-3-webview-js-bridge

GitHub GitHub package.json version

Install

yarn:

yarn add vue-webview-js-bridge

npm:

npm i vue-webview-js-bridge
// main.js
import { createApp } from "vue";
import AppLayout from "./layout/index.vue";
import VueJsBridge from 'vue-webview-js-bridge'

const app = createApp(AppLayout);
app.use(VueJsBridge);

// component.vue
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data () {
    return {
      code: ''
    }
  },
  mounted () {
    // Native call Web
    this.$bridge.registerHandler('handlerName', (data, callback) => {
      this.code = data
      console.log('data from native:', data)
      callback(data)
    })
  },
  methods: {
    async callNative () {
      // Web call Mobile
      this.$bridge.callHandler("handlerName", payload)
      .then((data) => {
        console.log('data',data)
      })
      .catch((error) => {
        console.log('error', error)
      });
    }
  }
}

Reference

vue-webview-js-bridge

License

MIT

About

License:MIT License


Languages

Language:JavaScript 94.8%Language:Shell 5.2%