美文网首页
ios和vue 互相调用

ios和vue 互相调用

作者: Sven0706 | 来源:发表于2018-06-22 11:46 被阅读0次
    在main.js 中将自定义方法绑定到vue原型中
    //oc和js互相调用
    Vue.prototype.setupWebViewJavascriptBridge = function (callback) {
        if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
        if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
        window.WVJBCallbacks = [callback];
        var WVJBIframe = document.createElement('iframe');
        WVJBIframe.style.display = 'none';
        WVJBIframe.src = 'https://__bridge_loaded__';
        document.documentElement.appendChild(WVJBIframe);
        setTimeout(function () { document.documentElement.removeChild(WVJBIframe) }, 0)
    }
    
    在组件中调用
    this.setupWebViewJavascriptBridge(function (bridge) {
      bridge.registerHandler('login', function(data, responseCallback) {
         this.login();
         responseCallback(data)
      })
      bridge.callHandler('closeBackItem', {'same':arr,'contain':['?t=']}, function(response) {})
    })
    

    相关文章

      网友评论

          本文标题:ios和vue 互相调用

          本文链接:https://www.haomeiwen.com/subject/kzhkyftx.html