在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ vue登陸后頁面數(shù)據(jù)渲染不上,刷新才好,怎么解決?

vue登陸后頁面數(shù)據(jù)渲染不上,刷新才好,怎么解決?

我在登陸頁面登錄成功后我把用戶信息放到了sessionstorage里,然后跳轉(zhuǎn)到用戶頁面,里面的組件獲取sessionstorage里面的數(shù)據(jù)然后渲染,但是發(fā)現(xiàn)第一次進(jìn)來時數(shù)據(jù)并沒有渲染上,刷新一次就好了,然后我在登陸后的頁面的組件比如nav里面的created和mounted里面打印sessionstorage,發(fā)現(xiàn)即使是第一次登陸也能打印出來,但是數(shù)據(jù)沒渲染上,這是怎么回事啊,求解?

//這是登錄頁面的
login() {
            console.log('登錄');

            this.$axios
                .post('/auth/login', {
                    // account: this.tel,
                    // password: this.password,
                    account: '11111111111',
                    password: '111111',
                })
                .then(res => {
                    const o = res.data;
                    console.log('ok');
                    this.$notify({
                        title: '登陸成功',
                        message: '歡迎回來',
                        type: 'success',
                    });
                    console.log(o.data);
                    sessionStorage.userInfo = JSON.stringify(o.data);
                    if (o.data.type == 1) {
                        console.log('teacher');         
                        this.$router.push({ path: 'teacher' });

                    }else{
                        this.$router.push({ path: 'agent' });

                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
//這是登陸后的頁面的導(dǎo)航頭部組件
export default {
    name: 'teaTopNav',
    data() {
        return {
            userInfo: {},
        };
    },

    
    created() {
        console.log('這是created');
        console.log(JSON.parse(sessionStorage.userInfo));
    },
    mounted() {
        console.log('這是mounted');
        console.log(JSON.parse(sessionStorage.userInfo));
        this.userInfo = this.GLOBAL.USERINFO;
        console.log(this.userInfo);
    },
    computed: {},

    methods: {
        quit() {
            this.$router.push({ path: '/' });
        },
    },
};
回答
編輯回答
不二心

teaTopNav 的模板貼出來看看

2018年1月4日 19:11
編輯回答
愚念

this.userInfo = this.GLOBAL.USERINFO 改成 this.userInfo = JSON.parse(sessionStorage.userInfo)不行么

2018年4月9日 15:38
編輯回答
哎呦喂

試試

this.$set(this, 'userInfo', JSON.parse(sessionStorage.userInfo))
2018年3月5日 18:23