//store/login.js
const state = {
token: window.localStorage.getItem('tokenAdmin'),
};
const getters = {
token(state) {
return state.token;
},
};
if (!this.getCookie('tokenAdmin')) {
window.location.href = '/login';
}
this.items - тут я так понимаю нужные данные лежат в goodGrid
setItems(res) {
this.items = res;
},
<InfiniteItems @:items="setItems" />
. Как мне с такой конструкцией компонентов передать их в <CardProduct/>
? this.goods = res.data.data;
this.$root.$emit('goods', this.goods);
data() {
return {
items:[],
},
mounted: function () {
this.$root.$on('goods', goods => {
this.items = goods
});
},
<button type="button" class="btn btn-green" @click="getAuth($event)">войти</button>
<nuxt-link to="/users_area" ref="button"></nuxt-link>
getAuth() {
let $this = $(e.target);
authParams['email'] = this.singLogin;
authParams['password'] = this.singPassword;
//axios. запрос
myObject.callApiPost('auth/login', authParams, '').then((res) => {
this.newToken = res.data;
document.cookie = 'token=' + this.newToken.data.token;
this.notAuth = res.data.error;
this.$root.$emit('isAuth', this.notAuth);
if (!this.notAuth) {
$this.$refs.button.click();
$('.fancybox-close').click();
}
}).catch((error) => {
alert(error)
this.errorAuth = true
});
},
TypeError: Cannot read property 'button' of undefined
<button type="button" class="btn btn-green" @click="getAuth()">войти</button>
<nuxt-link to="/users_area" ref="button"></nuxt-link>
getAuth() {
authParams['email'] = this.singLogin;
authParams['password'] = this.singPassword;
//axios. запрос
myObject.callApiPost('auth/login', authParams, '').then((res) => {
this.newToken = res.data;
document.cookie = 'token=' + this.newToken.data.token;
this.notAuth = res.data.error;
this.$root.$emit('isAuth', this.notAuth);
if (!this.notAuth) {
this.$refs.button.click();
$('.fancybox-close').click();
}
}).catch((error) => {
alert(error)
this.errorAuth = true
});
},
Через export const. И это. работает. Сейчас проблема именно в localStorage