在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) {})
})
网友评论