使用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框焦点问题目前使用的这个方法

                       maxlength="11" minlength="11" autofocus required>


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;
                            })
                    }
                }
            },

你可能感兴趣的:(使用vue开发项目遇到的一些问题)