使用vue开发项目遇到的一些问题

这个项目是我今年开始开发关于脚手架是使用的vue-cli(https://github.com/vuejs/vue-cli)

这边主要是记录几个我开发vue项目的经验

1、由于后台接口需要post请求可能需要的参数格式不同,一般情况都是json对象,但有的需要form格式

    而将json转换为form的代码为:

    let ret = ''
     for (let it in data) {
        ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
    }
    return ret

2、项目配置source与Tocken

需要在http,js中(项目架构可参考上方vue-cli地址)拦截器中

config.headers.source = `ddfd`;
        if (store.getters.getToken) {
            config.headers.AuthToken = `${store.getters.getToken}`;
        }

3、关于状态管理使用的是vuex,具体的可以参考官方文档

4、vue的一个开发问题input框焦点问题目前使用的这个方法

<input class="form-control login-border-radius"v-on:focus="isFocus" v-on:blur="loseBlur" :value="val" @input="foo($event)" type="text" placeholder="用户名" v-model="user.username"
                       maxlength="11" minlength="11" autofocus required></div>
loseBlur(e){
                this.val = e.target.value;
                if(this.val.length!=11){
                    this.isBlur=true;
                }
            },
            isFocus(){
                this.isBlur=false;
            },
            foo (e) {
                this.val = e.target.value;
                if (this.val.length!=11) {
                    this.getMsg=false;
                    this.isPhoneNum=true;
                    this.numberExist=1;
                }else if (this.val.length==11) {
                    this.isPhoneNum=/^1[3|4|5|8][0-9]\d{4,8}$/.test(this.val);
                    console.log(this.isPhoneNum=/^1[3|4|5|8][0-9]\d{4,8}$/.test(this.val))
                    this.getMsg=true;
                    if(this.isPhoneNum){
                        fetch(API.users.apiCheck+this.val)
                            .then(response => {
                                this.numberExist=response.result.exists*1;
                            })
                    }
                }
            },

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值