(以下所有接口由后台提供)
一、微信自动登录
//定义事件 methods:{ //判断是否微信登陆 是不是微信浏览器 isWeiXin() { let ua = window.navigator.userAgent.toLowerCase(); console.log(ua);//mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1 if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }, test(){ if(this.isWeiXin()){ //微信登录,接口由后台定义 this.$http.get('/wx/index/login/type/2').then((res) => { if(res.data.code==0){ //微信登录成功跳转个人中心 this.$router.push({ name:'UserHome', }) }else{ //微信登录失败,使用填写信息登录 this.$router.push({ name:'Login', }) } }) } //页面加载后执行 mounted(){ if(this.isWeiXin()){ //是来自微信内置浏览器 // 获取微信信息,如果之前没有使用微信登陆过,将进行授权登录 this.$http.get(this.$root.api+"/index/index/wx_info").then((res) => { if(res.data.code!=0){ location.href='/wx/index/wxAutoLogin'; } }) } }二、微信分享
methods:{ //判断是否微信登陆 isWeiXin() { let ua = window.navigator.userAgent.toLowerCase(); console.log(ua);//mozilla/5.0 (iphone; cpu iphone os 9_1 like mac os x) applewebkit/601.1.46 (khtml, like gecko)version/9.0 mobile/13b143 safari/601.1 if (ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }, //微信分享使用方法 wxInit(sd){ let links='http:///'} //当前网页链接,必须跟当前页面链接一样,单页面则以首页链接为准 $.post(url,data,function(res){ if(res.code == 0){ // 调用微信分享 old_this.wxInit(res.data); } }); } };以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。