center (center / cover) no-repeat;
baclground: url('../../img/bg.jpg') center / cover no-repeat;
// store
export const state = () => ({
functions: []
});
export const actions = {
async loadFunction({ commit }) {
try {
const plans = await Parse.Cloud.run('getFunction', {}, {});
commit('setFunction', plans);
} catch (error) {
commit('setFunction', null);
return null;
}
},
};
export const mutations = {
setFunction: (state, payload) => {
state.functions = payload;
}
}
// Ваш копонент, где вы отображаете TItem
<template>
<div>
<TItem
v-for="(item, index) in functions"
:key="index"
:tplan="item"
@delete="deleteItem(index)"
/>
</div>
</template>
<script>
import { mapState } from 'vuex'
export default {
//....
computed: {
...mapState([
'functions'
])
}
//...
}
</script>
// ./services/api.js
import axios from 'axios';
// Проверим в самом начале, есть ли токен в хранилище
const JWTToken = localStorage.getItem('jwt');
// Создать инстанс axios
const api = axios.create({
baseURL: `${BASE_URL}/api`;
});
function apiSetHeader (name, value) {
if (value) {
api.defaults.headers[name] = value;
}
};
// Если токен есть, то добавим заголовок к запросам
if (JWTToken) {
apiSetHeader('Authorization', `Bearer ${JWTToken}`);
}
api.interceptors.request.use(config => {
// Если пользователь делает запрос и у него нет заголовка с токеном, то...
if (!config.defaults.headers['Authorization']) {
// Тут пишем редирект если не авторизован
}
return config;
}, error => {
return Promise.reject(error);
});
export default api;
export apiSetHeader
// ./services/sign-in.js
import api, { apiSetHeader } from './api'
export const authorize = async (username, password) => {
try {
const { data } = await api.post('/clients/token/', {
username,
password
});
localStorage.setItem('jwt', data.access);
apiSetHeader('Authorization', `Bearer ${data.access}`);
} catch (error) {
console.log(error);
}
};
let template = '';
data.forEach(item => {
template += `<div class="name">${item .name}</div>`;
let brands = '';
item.brands.forEach(brand => {
brands += `${brand .name}, `;
});
template += `<div class="brands">${brands}</div>`;
});
$('.category_brands').html(template);
подскажите насколько актуальна сейчас в 2020 и в 2021
// Создать массив дней
const days = ['Понедельник', 'Вторник'] // и т.п.
// Получить индекс дня недели
const cuttentDayIndex = new Date().getDay();
// Получить из массива название дня недели по индексу.
// Но т.к. дни недели в getDay начинаются с 1, то вторник будет 2, а раз массивы считаются с 0, то вычитаем - 1
const currentDay = days[cuttentDayIndex - 1];
<template>
<ul>
<li :class="{ active: currentDay === 'Понедельник'}">Понедельник</li>
<li :class="{ active: currentDay === 'Вторник'}">Вторник</li>
</ul>
</template>
<script>
data: () => ({
days: ['Понедельник', 'Вторник'] // и т.п.
}),
computed: {
currentDay () {
const cuttentDayIndex = new Date().getDay();
return this.days[cuttentDayIndex - 1]
}
}
</script>
computed: {
newArray () {
return this.arr.filter(item => item.id === this.active.id)
}
}
let posX = 0;
let posY = 0;
document.addEventListener('touchmove', event => {
const { clientX, clientY } = event.touches[0];
if (posY < clientY) {
console.log('Вниз')
}
if (posY > clientY) {
console.log('Вверх')
}
posX = clientX;
posY = clientY;
})