获取后台返回的URL中的Token

获取后台返回的URL中的Token

App.vue中

// An highlighted block
 methods: {
init() {
    var url = window.location.href;
    //access_token是后台所指定的key
    if (url.indexOf('access_token') != -1) {
        //登录跳转
        let str = url.split('#')[1];
        let a = url.split('#')
        let arr = str.split('&');
        let json = {};
        let token = '';
        let state = '';
        let tenant = '';
        let userid = '';
        for (var i = 0; i < arr.length; i++) {
            let arr2 = arr[i].split('=');
            json[arr2[0]] = arr2[1];
        }
        token = json['/access_token'];
        tenant = json['tenant_id'];
        userid = json['user_id'];
        let user = json['username'];
        this.$router.push({ path:'/'})
        this.$cookies.set('CookieToken', token)
        console.log('查看所有cookie=',this.$cookies.keys())
        console.log('查看返回的url中的所有信息=json==', json)
    } else {
       //做登录跳转
    }
                
},

你可能感兴趣的:(Vue,cookie)