.ranging {
display: none;
}
.ranging.opened {
display: block;
}
const buttonSelector = '.selector';
const contentSelector = '.ranging';
const activeClass = 'opened';
const toggleContent = (contents, index) =>
contents.forEach((n, i) => n.classList.toggle(activeClass, i === index));
// делегирование, назначаем обработчик клика один раз для всех кнопок
// наверное, у них есть какой-то общий предок, тогда вместо документа
// вешать обработчик следует на него:
// document.querySelector('селектор_контейнера_с_кнопками').addEventListener(...
document.addEventListener('click', e => {
const button = e.target.closest(buttonSelector);
if (button) {
const buttons = document.querySelectorAll(buttonSelector);
const index = Array.prototype.indexOf.call(buttons, button);
toggleContent(document.querySelectorAll(contentSelector), index);
}
});
// или, назначаем обработчик клика индивидуально каждой кнопке
const onClick = function(e) {
toggleContent(this, +e.currentTarget.dataset.index);
}.bind(document.querySelectorAll(contentSelector));
document.querySelectorAll(buttonSelector).forEach((n, i) => {
n.dataset.index = i;
n.addEventListener('click', onClick);
});
в created() пишет localStorage или document is not defined <...> nuxt
if (process.client) {
// здесь можете пощупать localStorage
}
Документация прочитана, наверно не настолько внимательно, чтобы понять
check-in-changed
и check-out-changed
.filters: [
{ name: 'calculator.brand_filter', getter: obj => obj.brand.name, value: '' },
{ name: 'calculator.company_filter', getter: obj => obj.company.name, value: '' },
{ name: 'calculator.country_filter', getter: obj => obj.brand.country, value: '' },
{ name: 'calculator.side_filter', getter: obj => obj.sides, value: '' },
],
computed: {
filteredProfiles() {
return this.filters.reduce((profiles, { value, getter }) => {
return value
? profiles.filter(n => getter(n) === value)
: profiles;
}, this.profiles);
},
Vue.component('filter-select', {
props: [ 'name', 'options', 'value' ],
template: `
<div>
<p>{{ name }}<p>
<select :value="value" @change="$emit('input', $event.target.value)">
<option value="">-</option>
<option v-for="n in options">{{ n }}</option>
</select>
</div>`
});
computed: {
filterOptions() {
return this.filters.map(n => [...new Set(this.profiles.map(n.getter))]);
},
<filter-select
v-for="(n, i) in filters"
v-model="n.value"
:options="filterOptions[i]"
:name="trans(n.name)"
></filter-select>
methods: {
resetFilters() {
this.filters.forEach(n => n.value = '');
},
<button @click="resetFilters">{{ trans('calculator.reset_filter') }}</button>
<select v-model="brand" class="custom-select">
filteredProfiles() {
return this.profiles.filter(n => n.brand.name === this.brand);
},
<div v-for="profile in filteredProfiles" class="row feed">
pointer-events: none
для #box и pointer-events: all
для :before и button .tab-content__item {
display: none;
}
.tab-content__item.active {
display: list-item;
}
.tab-header__item.active {
color: red;
}
const headerSelector = '.tab-header__item';
const contentSelector = '.tab-content__item';
const activeClass = 'active';
// делегирование, обработчик клика добавляется один раз для всех хедеров;
// контент, соответствующий нажатому хедеру, определяем через равенство data-атрибутов
document.addEventListener('click', e => {
const header = e.target.closest(headerSelector);
if (header) {
const { tab } = header.dataset;
const toggle = n => n.classList[n.dataset.tab === tab ? 'toggle' : 'remove'](activeClass);
document.querySelectorAll(headerSelector).forEach(toggle);
document.querySelectorAll(contentSelector).forEach(toggle);
}
});
// или, обработчик клика добавляется каждому хедеру индивидуально;
// контент, соответствующий нажатому хедеру, определяем по равенству индексов
const headers = document.querySelectorAll(headerSelector);
const contents = document.querySelectorAll(contentSelector);
headers.forEach(n => n.addEventListener('click', onClick));
function onClick() {
const index = Array.prototype.indexOf.call(headers, this);
const toggle = (n, i) => n.classList[i === index ? 'toggle' : 'remove'](activeClass);
headers.forEach(toggle);
contents.forEach(toggle);
}
i * 4000
на (i * 2 + 1) * 1000
- чтобы таймауты не совпадали <input id="min" type="number" value="25"> -
<input id="max" type="number" value="75">
<div id="range"></div>
const values = {
min: 0,
max: 100,
};
const range = $('#range').ionRangeSlider({
type: 'double',
grid: true,
...values,
onChange(e) {
$('#min').val(e.from);
$('#max').val(e.to);
},
}).data('ionRangeSlider');
$('#min, #max').attr(values).on('input', function() {
const v = [ $('#min').val(), $('#max').val() ]
.sort((a, b) => a - b)
.map(n => Math.max(values.min, Math.min(values.max, +n)));
$('#min').val(v[0]);
$('#max').val(v[1]);
range.update({
from: v[0],
to: v[1],
});
}).trigger('input');
<input id="min" type="number" value="25"> -
<input id="max" type="number" value="75">
<div id="range"></div>
const values = {
min: 0,
max: 100,
};
$('#range').slider({
range: true,
...values,
slide(e, ui) {
$('#min').val(ui.values[0]);
$('#max').val(ui.values[1]);
},
});
$('#min, #max').attr(values).on('input', function() {
const v = [ $('#min').val(), $('#max').val() ]
.sort((a, b) => a - b)
.map(n => Math.max(values.min, Math.min(values.max, +n)));
$('#min').val(v[0]);
$('#max').val(v[1]);
$('#range').slider('values', v);
}).trigger('input');
const reg = new RegExp(`(.+).{${symbolsForHide}}$`);
$('.phone_number')
.attr('data-phone', function() {
return $(this).text()
})
.text((i, text) => text.replace(reg , '$1...'));
const
$this = $(this),
$phone = $this.siblings('.phone_number'),
phone = $phone.data('phone');
$phone.text(phone).attr('href', `tel: ${phone}`);
$this.remove();
:license="{
old_price: 20,
price: 200,
title: 2,
}"
computed: {
brands() {
return [...new Set(this.profiles.map(n => n.brand.name))];
},
},
<option v-for="brand in brands" :value="brand">{{ brand }}</option>
const router = new VueRouter({
routes: [
{ path: '/', component: { template: '<div>Home</div>' } },
{ path: '/foo', component: { template: '<div>Foo</div>' } },
{ path: '/boo', component: { template: '<div>Boo</div>' } },
],
});
new Vue({
router,
el: '#app',
data: () => ({
routeIndex: 0,
}),
created() {
setInterval(() => {
const { routes } = this.$router.options;
this.routeIndex = (this.routeIndex + 1) % routes.length;
this.$router.push(routes[this.routeIndex]);
}, 1000);
},
});
<div id="app">
<router-view></router-view>
</div>
const key = 'prop';
const val = 1;
const result = array.flatMap(n => n.filter(m => m[key] === val));
// или
const result = array.reduce((acc, n) => (
n.forEach(m => m[key] === val && acc.push(m)),
acc
), []);
// или
const result = [];
for (const n of [].concat(...array)) {
if (n[key] === val) {
result[result.length] = n;
}
}
получает следующие аргументы <...> При определении в модуле
state, // при использовании модулей — локальный state модуля getters, // локальные геттеры текущего модуля rootState, // глобальный state rootGetters // все геттеры