javascript - vue渲染json 有问题
巴扎黑
巴扎黑 2017-04-11 12:16:34
[JavaScript讨论组]
var req = superagent;
var vm = new Vue({
    'el': 'body',
    'data': {
        'mobile': null,
        'mobile_error': false,
        'mobile_error_text': '',
        'code': null,
        'code_error': false,
        'code_error_text': '',
        'code_show': false,
        'btn_send_lock': true,
        'btn_send_timer': null,
        'btn_login_lock': true,
        'btn_login_timer': null,
// alert(API.login)
    },
    'created': function(){
        // 旋转动画
        setTimeout(function() {
            var el = document.getElementById('j-left')
            var classname = el.className;
            el.className = classname + ' rotate';
        }, 3000);        
    },
    'methods': {
        'checkMobile': function() {
            var isMobile = /^(13[012356789][0-9]{8}|15[012356789][0-9]{8}|18[02356789][0-9]{8}|147[0-9]{8}|1349[0-9]{7})$/;
            // 校验电话号是否为空
            if (null == this.mobile || '' == this.mobile) {
                this.mobile_error = true;
                this.mobile_error_text = '电话号码不能为空!';
            } else if (!isMobile.test(this.mobile)) {
                this.mobile_error = true;
                this.mobile_error_text = '电话号码格式错误!';
            } else {
                this.mobile_error = false;
                this.btn_send_lock = false;
                this.mobile_error_text = '';
            }
        },
        'sendMobile': function() {
            this.checkMobile();
            if (!this.mobile_error && !this.btn_send_lock) {
                this.btn_send_lock = false;
                clearTimeout(this.btn_login_timer);
                this.btn_login_timer = setTimeout(function() {
                    this.btn_send_lock = true;
                    req.post(API.sendSms)
                        .send({
                            'mobile_phone': vm.mobile
                        })
                        .set('Content-Type', 'application/x-www-form-urlencoded')
                        .set('X-Requested-With', 'XMLHttpRequest')
                        .accept('application/json')
                        .end(function(err, res) {
                            this.btn_send_lock = false;
                            if (err || !res.ok) {
                                alert('网络异常, 请刷新重试!');
                            } else {
                                var json = res.body;
                                if (1 == json.status) {
                                    vm.code_show = true;
                                } else {
                                    alert(json.info);
                                }
                            }
                        })
                }, 500);
            }
        },
        'checkCode': function(){
            if(null == this.code || '' == this.code){
                this.code_error = true;
                this.code_error_text = '请输入验证码!';
                this.btn_login_lock = true;
                return false;
            } else if( 4 != this.code.length) {
                this.code_error = true;
                this.code_error_text = '验证码长度位4位!';
                this.btn_login_lock = true;
                return false;
            } else {
                this.code_error = false;
                this.code_error_text = '';
                this.btn_login_lock = false;
                return true;
            }
        },
        'login': function() {
            if (this.checkCode()) {
                vm.btn_login_lock = true;
                clearTimeout(this.btn_send_timer);
                this.btn_send_timer = setTimeout(function() {
                    req.post(API.login)
                        .send({
                            'mobile_phone': vm.mobile,
                            'code': vm.code
                        })
                        .set('Content-Type', 'application/x-www-form-urlencoded')
                        .set('X-Requested-With', 'XMLHttpRequest')
                        .accept('application/json')
                        .end(function(err, res) {
                            // vm.btn_login_lock = false;
                            if (err || !res.ok) {
                                alert('网络异常, 请刷新重试!');
                            } else {
                                var json = res.body;
                                if (1 == json.status) {
                                    window.location.href = json.url;
                                } else {
                                    alert(json.info);
                                }
                            }
                        })
                }, 500);
            } else {
            }
        }
    }
});
js文件




    
    
    家家户户活动管理平台?ver=2.0
    
    
    
    



    

发送验证码

登录

{{d.site_id}}:{{d.site_name}}

源文件

巴扎黑
巴扎黑

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号