代码很简洁,直接上代码
function shareGoodsDtails() {
let data = {
'url': "",
'name': "shareGoodsDtails",
"goodsName": '来拿不要钱~免费好礼,不要白不要呢!',
'goodsThumbnailUrl': 'http://xiaolvlan.oss-cn-hangzhou.aliyuncs.com/share/share0yuan.png',
"goodsTitle": '新人特权首单0元,更多好礼等你选'
}
if (/android/i.test(navigator.userAgent)) {
try {
let _data = JSON.stringify(data)
window.android.shareGoodsDtails(_data); //此处是Android的交互,方法名是shareGoodsDtails
} catch (e) {
console.log('与android链接中断')
}
} else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
try {
window.webkit.messageHandlers.shareGoodsDtails.postMessage(data); //此处是ios的交互,方法名是shareGoodsDtails
} catch (e) {
console.log('与ios链接中断')
}
}
}
在vue里面的话,把方法挂载到window上即可
window.shareGoodsDtails=function(){
let data = {
'url': "",
'name': "shareGoodsDtails",
"goodsName": '来拿不要钱~免费好礼,不要白不要呢!',
'goodsThumbnailUrl': 'http://xiaolvlan.oss-cn-hangzhou.aliyuncs.com/share/share0yuan.png',
"goodsTitle": '新人特权首单0元,更多好礼等你选'
}
if (/android/i.test(navigator.userAgent)) {
try {
let _data = JSON.stringify(data)
window.android.shareGoodsDtails(_data); //此处是Android的交互,方法名是shareGoodsDtails
} catch (e) {
console.log('与android链接中断')
}
} else if (/ios|iphone|ipod|pad/i.test(navigator.userAgent)) {
try {
window.webkit.messageHandlers.shareGoodsDtails.postMessage(data); //此处是ios的交互,方法名是shareGoodsDtails
} catch (e) {
console.log('与ios链接中断')
}
}
}
网友评论