const ParamsAffiliate = localStorage.getItem("ParamsAffiliate");
if(ParamsAffiliate){
this.ParamsAffiliate = JSON.parse(ParamsAffiliate);
return;
}
axios.get('/information/userbar/account')
.then(response => {
this.ParamsAffiliate = response.data;
localStorage.setItem('ParamsAffiliate', JSON.stringify(response.data))
})
import axios from 'axios';
export default new vuex.Store({
state: {
params: null,
},
mutations:{
setParams(state, payload){
state.params = payload;
}
},
actions: {
async getParams({commit, state}){
let response = await axios.get('/information/userbar/');
if (response.status === 200) {
commit('setParams', response.data);
}
}
}
});
component.vue
import { mapState } from 'vuex';
export default {
name: 'IdWeb',
computed: {
...mapState([
'params'
])
},
mounted() {
this.$store.dispatсh('getParams');
},
}
<template>
<li class="state_account_id" v-if="params">
ID: {{params.id}}
</li>
</template>
new Vue({
data() {
return {
ParamsAffiliate: ''
}
},
mounted() {
this.getParams();
},
methods: {
getParams(){
const ParamsAffiliate = localStorage.getItem("ParamsAffiliate");
if(ParamsAffiliate){
this.ParamsAffiliate = JSON.parse(ParamsAffiliate);
return;
}
axios.get('/information/userbar/')
.then(response => {
this.ParamsAffiliate = response.data;
localStorage.setItem('ParamsAffiliate', JSON.stringify(response.data))
})
}
}
});
ID: {{ParamsAffiliate.id}}
export default {
name: 'IdWeb',
data() {
return {
ParamsAffiliate: ''
}
},
mounted() {
this.getParams()
},
methods: {
getParams(){
this.$root.getParams()
}
}
}