最近在用vue写商城H5,打算嵌入到原生app中,但是在调用原生android方法时,却发现调不到android提供的方法
这是我调用原生app的方法
代码在html页面中 android是好用的,请问一下vue中调原生方法和html中有什么不同吗?
求谁能帮我看看原因
vue下的方法
callPhone(){
let params = {
photoUrl: "http://img.minweixian.com/webfile/purchase/qrcode_test.jpg",
title:"测试"
};
if (/android/i.test(navigator.userAgent)) {
// try {
state.Toast.fail("我是安卓"+!window["android"]) //找不到window["android"]
window.android.orderPhotoxz(params.photoUrl,params.title);
} else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
try {
window.webkit.messageHandlers.tel.postMessage(params);
} catch (e) {
console.log(e);
}
}
}
html下的方法
function save() {
var params = {
photoUrl: "http://img.minweixian.com/webfile/purchase/qrcode_test.jpg",
title:"测试"
};
if (/android/i.test(navigator.userAgent)) {
try {
alert(params.photoUrl+";"+params.title);
window.android.orderPhotoxz(params.photoUrl,params.title);
} catch (e) {
console.log(e);
}
} else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
try {
window.webkit.messageHandlers.orderPhotoxz.postMessage(params);
} catch (e) {
console.log(e);
}
}
}
加个延时试试