vue3-webview-js-bridge
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

vue-3-webview-js-bridge

GitHub GitHub package.json version

Install

yarn:

yarn add vue3-webview-js-bridge

npm:

npm i vue3-webview-js-bridge

Example

// main.js
import { createApp } from "vue";
import App from './App.vue'
import VueJsBridge from 'vue3-webview-js-bridge'

const app = createApp(App);
app.use(VueJsBridge, {
	debug: true,
	nativeHandlerName: 'testObjcCallback',
	mock: true,
	mockHandler(payload, next) {
		// mock by payload
		// call next(data) to mock data
	}
	// ...
})

// 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

Package Sidebar

Install

npm i vue3-webview-js-bridge

Weekly Downloads

2

Version

0.0.11

License

MIT

Unpacked Size

39 kB

Total Files

13

Last publish

Collaborators

  • hexiaoleione