微信H5网页使用扫一扫时遇到的问题
首次进入界面调用失败
问题:进入页面,点击扫一扫按钮调用微信扫一扫功能失效,但是刷新当前页调用就正常了
解决方法:
// 使用扫一扫按钮的页面
import * as auth from '@/utils/auth';
mounted() {
// 临时解决扫一扫刷新问题
if (auth.getUrlCode() == 1) {
auth.removeUrlCode()
} else {
auth.setUrlCode(1);
location.reload();
}
},
// auth.js页面
import Cookies from 'js-cookie'
// 存储临时code
export function setUrlCode(code){
return Cookies.set('urlCode',code)
}
// 获取临时code
export function getUrlCode() {
return Cookies.get('urlCode')
}
// 移出临时code
export function removeUrlCode() {
return Cookies.remove('urlCode')
}