vue.js - vue-resource怎么获取返回的data?

查看:146
本文介绍了vue.js - vue-resource怎么获取返回的data?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

像jquery的ajax从后台获取数据时,可以直接data.msg,但是用这个vue-resource该怎么读取到返回的msg字符串呢?就是下方登录失败四个字,想替换成类似data.msg的东西,该怎么做呢?

methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        var data = {
                            _token: "lKwaNM6vINbPsPWHFAX9fnDxCIWc73FGikUSRnq31",
                            username:this.ruleForm2.pass,
                            password:this.ruleForm2.checkPass
                        };
                        this.$http.post('/secure/signIn', data).then((response) => {
                            //success
                            this.$message({
                                message: '登录成功!',
                                type: 'success',
                                duration: '1000'
                            });
                            window.location.href = "http://test.administer/index#/homepage";
                        }, (response) => {
                            //failed
                            this.$message({
                                message: "登录失败",
                                type: 'error',
                                duration: '1200'
                            });
                        });
                    } else {
                        return false;
                    }
                });
            }
        }

解决方案

methods: {
            submitForm(formName) {
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        var data = {
                            _token: "lKwaNM6vINbPsPWHFAX9fnDxCIWc73FGikUSRnq31",
                            username:this.ruleForm2.pass,
                            password:this.ruleForm2.checkPass
                        };
                        this.$http.post('/secure/signIn', data).then((response) => {
                            //success
                            this.$message({
                                message: '登录成功!',
                                type: 'success',
                                duration: '1000'
                            });
                            window.location.href = "http://ikeeko.administer/index#/homepage";
                        }, (response) => {
                            //failed
                            this.$message({
                                message: response.data.msg,
                                type: 'error',
                                duration: '1200'
                            });
                        });
                    } else {
                        return false;
                    }
                });
            }
        }

这篇关于vue.js - vue-resource怎么获取返回的data?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆