组件global,用于存放用户登录信息。
global.vue
const CLIENT_ID = '';
const USER_INFO = {};
const SESSION_GLOBAL = {};
export default {
CLIENT_ID,
USER_INFO,
SESSION_GLOBAL
}
header.vue
import global from '../../components/global/global.vue';
created(){
let cookie_arr = document.cookie.split(';');
for(let i = 0; i < cookie_arr.length; i++){
let cookieArrTrim = cookie_arr[i].trim();
if(cookieArrTrim.indexOf('client_id') == 0){
global.CLIENT_ID = cookieArrTrim.substring('client_id'.length + 1, cookieArrTrim.length);
if(global.CLIENT_ID !== ''){
this.$http.get('http://192.168.1.5/app/getClient.action', {
params: {
'clientId': global.CLIENT_ID
}
}).then(response => {
response = response.body;
global.USER_INFO = response.object;
this.user_info.avatar = global.USER_INFO.imgUrl;
this.user_info.user_name = global.USER_INFO.nickName;
this.user_info.phone = global.USER_INFO.phone;
console.log(global);
})
}
}
else{
return;
}
}
}
console.log(global);
sell_car.vue
import global from '../../components/global/global.vue';
console.log(global.CLIENT_ID);
但打印global是可以获取到的。
在safari和chrome里只有点开对象才能看见值,firefox里可以直接看到。