vue调用原生的方法
var u = navigator.userAgent; var isAndroid = u.indexOf("Android") > -1 || u.indexOf("Adr") > -1; //android安卓 var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios苹果 if (isAndroid) { window.android.pay(); // 或者 // Android.pay(JSON.stringfy(params)); // 传参给安卓 let params={ name:"123", age:"123" } Android.pay(JSON.stringfy(params)); } else if (isiOS) { window.webkit.messageHandlers.pay.postMessage(null); }
vue放出方法让原生调用
<script> export default { mounted() { let that = this; window.orderSuccess = that.orderSuccess; window.orderFailed = that.orderFailed; }, methods: { // 支付成功 orderSuccess() { console.log("支付成功"); }, // 支付失败 orderFailed() { console.log("支付失败"); } } }; </script>
标签:原生,vue,orderSuccess,pay,window,params,Android,交互 From: https://www.cnblogs.com/chenzhengyang/p/17190989.html