项目中遇到的问题总结(第一个项目)

<h3 id="授权绑定微信公众号微信网页授权">1.授权绑定微信公众号(微信网页授权)

mounted:function() {
    var uid = tools.cookie.get('id') //cookie缓存微信id
    if(uid == undefined ){//判断是否登录
        var _this = this;
        var data = tools.getHrefData();
        var code = data.code;
        if(code){
            _this.getWxInfo(code,function(wxInfo){
                tools.ajax(  //tools  封装的函数
                    server.wx_register,//上传微信号
                    {
                        data:{
                            'wx_code': wxInfo.openid,sname: wxInfo.nickname,sex: wxInfo.sex,headimgurl: wxInfo.headimgurl
                        },success:function(res){
                            if(res &amp;&amp; res.retcode == 200){

                                tools.cookie.set('data',JSON.stringify(res.data))
                                var data=JSON.parse(tools.cookie.get('data'))

                                var userid= data.id;
                                tools.cookie.set('id',userid)
                                var id = tools.cookie.get('id')



                            }else{
                                _this.$vux.toast.show({
                                        type: 'text',text: res.msg
                                })
                            }
                        }
                    }
                )

        });
    }
    else {//微信网页授权
         var weixinUrl = '';
          weixinUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa0da85c9b3d8682d&amp;redirect_uri=http://www.yiyisoft.net/ysxdwy/Public/www/index.html&amp;response_type=code&amp;scope=snsapi_userinfo&amp;state=1#wechat_redirect';
          window.location.href = weixinUrl;
    }
    }else{
        return false;
    }           

},methods: {
getWxInfo:function(code,fn){
var _this = this;
tools.ajax(server.wx_info,{ // server.wx_info 后端接口
data:{
code:code,type: 'weixin',isWeChat: true
},success:function(res){
if(res.code == 1){
var wxInfo = JSON.parse(res.data);
fn&&fn(wxInfo);
}else{
_this.$vux.toast.show({//_this.$vux.toast.show vux里的toast
type: 'text',text: res.msg
})
}
},error:function(){
_this.$vux.toast.show({
type: 'text',text: "微信授权失败"
})
}
})
}
}


<h3 id="路由跳转到指定页面的指定位置">2.路由跳转到指定页面的指定位置

  • A页面跳转到B页面指定位置

    this.$router.push({path:"login",params:{name:'share-login'}});

    1. path -> 是要跳转的路由路径,也可以是路由文件里面配置的 name 值,两者都可以进行路由导航
    1. params -> 是要传送的参数,参数可以直接key:value形式传递
    1. query -> 是通过 url 来传递参数的同样是key:value形式传递

html