项目中遇到的问题总结(第一个项目)
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 && 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&redirect_uri=http://www.yiyisoft.net/ysxdwy/Public/www/index.html&response_type=code&scope=snsapi_userinfo&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: "微信授权失败" }) } }) } }
2.路由跳转到指定页面的指定位置
A页面跳转到B页面指定位置
this.$router.push({path:"login",params:{name:'share-login'}});
- path -> 是要跳转的路由路径,也可以是路由文件里面配置的 name 值,两者都可以进行路由导航
- params -> 是要传送的参数,参数可以直接key:value形式传递
- query -> 是通过 url 来传递参数的同样是key:value形式传递
3.实时统计textarea输入字数并限制字数
html
<div class="row"> <div class="ance-title">分享我的故事</div> <textarea class="limit_2000 advice" placeholder="提示:请注意保护个人隐私" v-model.trim="article"> </textarea> *可输入字数0/2000 </div>
less
.row{ position: relative; .ance-title{ width: 100%; height: 35px; background: yellow; padding: 5px 5px 5px 20px; box-sizing: border-box; } .advice { width: 100%; height: 300px; overflow-y: scroll; border: none; padding: 10px 20px; box-sizing: border-box; font-size: 14px; &::-webkit-scrollbar { display: none; } } @media( min-width: 320px) and(max-width:374px){ .advice { height: 250px; } } .limit { position: absolute; top: 5px; right: 5px; } }
jquery
//以下代码为了兼容iOS、Android var bind_name = 'input'; if(navigator.userAgent.indexOf("MSIE") != -1) {//(此处是为了兼容IE)navigator.userAgent.indexOf来判断浏览器类型 bind_name = 'propertychange'; } if(navigator.userAgent.match(/androdid/i) == "android"){ bind_name = 'keyup'; }; //截取限制字符长度 $(".limit_2000").bind(bind_name,function(){ var limitSub = $(this).val().substr(0,2000); $(this).val(limitSub); //截取字符长度 $(this).next(".statistics").html('*可输入字数'+limitSub.length+'/2000');//获取实时输入字符长度并显示 if(limitSub.length == 2000) { $(".limit").css("color","red"); //超出指定字符长度标红提示 }else { $(".limit").css("color","#333"); } });
4.输入手机号获取验证码
vue文件
<div class="login-list"> <div class="login"> <img src="../assets/images/3.png" alt=""> <input type="tel" maxlength="11" placeholder="请输入您的手机号码" v-model.trim="user_tel"> </div> <div class="login"> <img src="../assets/images/4.png" alt=""> <input type="tel" maxlength="6" placeholder="请输入验证码" v-model.trim="verify_code"> <button v-show="sendCode" class="send" @click="getCode">验证码</button> <button v-show="!sendCode" class="again" v-bind="{'disabled':disabled}">{{send_time}}秒后重发</button> </div> <div class="login"> <button class="btns btn-warning" @click="confirm">确认</button> <button class="btns btn-gray">返回</button> </div> </div> export default { data: function() { return { user_tel: '', verify_code: '', disabled: false } }, methods: { // 获取验证码 getCode() { var _this = this var regphoto = 11&& /^((13|14|15|17|18)[0-9]{1}\d{8})$/;//手机号正则验证 if(_this.user_tel =="") { _this.$vux.toast.show({ type: 'text', text: '请输入手机号' }) return; }else if(!regphoto.test(_this.user_tel)) { _this.$vux.toast.show({ type: 'text', text: '输入正确的手机号' }) return; }else { //60秒之后重发验证码 _this.sendCode = false; _this.send_time = 60; var timer = setInterval(()=>{ _this.send_time--; if(_this.send_time<=0){ _this.sendCode = true; clearInterval(timer); _this.disabled = false; } },1000); tools.ajax( url地址(后端给的), { data:{ user_tel: _this.user_tel, }, success:function(res){ if(res && res.retcode == 200){ console.log(res.data) }else{ _this.$vux.toast.show({ type: 'text', text: res.msg }) } }, error:function(err){ _this.$vux.toast.show({ type: 'text', text: '请求失败' }) } } ) } } }, // 确认登录 confirm() { var _this = this var regphoto = 11&& /^((13|14|15|17|18)[0-9]{1}\d{8})$/;//手机号正则验证 if (_this.user_tel == "") { _this.$vux.toast.show({ type: 'text', text: '请输入手机号' }) return; }else if(!regphoto.test(_this.user_tel)){ _this.$vux.toast.show({ type: 'text', text: '手机号填写有误' }) return; }else if(_this.verify_code == ""){ _this.$vux.toast.show({ type: 'text', text: '请输入验证码' }) return; }else{ var uid = tools.cookie.get('id') var id = tools.cookie.get('wenid') tools.ajax( 地址, { data:{ user_tel: _this.user_tel, verify_code: _this.verify_code }, success:function(res){ if(res && res.retcode == 200){ _this.toggle = !_this.toggle; _this.$vux.toast.show({ type: 'success', text: '提交成功' }) setInterval(()=>{ window.location.href='成功之后跳转的地址' },2000) }else{ _this.$vux.toast.show({ type: 'text', text: res.msg }) } }, error:function(err){ _this.$vux.toast.show({ type: 'text', text: '请求失败' }) } } ) } } }
相关推荐
softwear 2020-08-21
ZGCdemo 2020-08-16
northwindx 2020-05-31
zrtlin 2020-11-09
xuebingnan 2020-11-05
wikiwater 2020-10-27
heheeheh 2020-10-19
Crazyshark 2020-09-15
jczwilliam 2020-08-16
littleFatty 2020-08-16
idning 2020-08-03
jinxiutong 2020-07-26
lanzhusiyu 2020-07-19
Skyline 2020-07-04
xiaofanguan 2020-06-25
Aveiox 2020-06-23