android + vue的注意事项
访问量: 2954
1. 不要使用 onPageStarted, onPageFinished 等这样根据url来监听页面变化 的方法来各种跳转. 务必使用 android js bridge.
2. 修改android 之后,记得务必 SHIFT + F10. 重新编译. 否则看不掉效果.
3. 务必每次请求url 都要加上 client=android 这样的参数.
4. (如果使用了android js bridge就不必担心这个问题了)每次打开页面,或者使用ajax请求时,都会出发 onPageFinished 这个函数. 所以,如果你发现一个webview会出发多个 onPageFinished的话,不用担心,那是你的ajax请求触发的.
5. to.query.client 与 from.query.client 是两个不同的东西. 下面的函数通常用于组织当前Activity的Webview中的url跳转(vue2.0特性)
router.beforeEach((to, from, next) => { console.info(to) console.info(from) console.info('跳转了') let link if (to.query.client === 'ios') { link = true } else if (from.query.client === 'ios'){ console.info('full_path ===' + to.fullPath) window.location.href = 'http://link_to' + to.fullPath link= false } else if (from.query.client === 'android'){ // 注意这里, 必须是from.query.client, 不能是to.query.client, 否则不会正确识别 /#/xx?client=android console.info('== by android' ) console.info('to.full_path: ' + to.fullPath) // 如果要打开的页面是: 装修服务详情页, 起始页面是:首页,/home console.info("from.full_path: " + from.fullPath) if(to.fullPath.includes('zhuang_xiu_fu_wu_show')){ link = to.query.is_open_new_activity === 'true' console.info("== link is: " + link) }else{ } } else { console.info("== in else next(link) function, 如果看到这一句,说明在android中是有问题的") link = true } next(link) })