data: () => ({
items: [
{ buttonText: '+', className: 'container' },
{ buttonText: '-', className: 'container-fluid' },
],
...
}),<button
v-for="n in items"
v-text="n.buttonText"
:class="{ active : active === n.className }"
@click="active = n.className"
></button>
items.slice... надо было унести в computed):<div v-for="item in items.slice((page - 1) * perPage, page * perPage)">
{{ item }}
</div>computed: {
numPages() {
return Math.ceil(this.items.length / this.perPage);
},
},methods: {
next(change) {
this.page = Math.max(1, Math.min(this.numPages, this.page + change));
},
},<button @click="next(-1)" :disabled="page <= 1">prev</button>
<button @click="next(+1)" :disabled="page >= numPages">next</button>
{ path: '/city', component: City, props: () => ({ cityid: app.cityid }) }<router-view :cityid="cityid"></router-view>
validate = true;
if (/* проверка введённых данных */) {
validate = false;
}validate = /* проверка введённых данных */
arr.sort(({ date: a }, { date: b }) => !a ? 1 : !b ? -1 : a - b);
// или
arr.sort((a, b) => (a.date || Infinity) - (b.date || Infinity));const sortedArr = arr
.map(n => [ n, n.hasOwnProperty('date') ? n.date : Number.MAX_SAFE_INTEGER ])
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
function toggleWithInterval(selector, delay) {
let index = -1;
return setInterval(function($items) {
$items.eq(index).hide();
index = (index + 1) % $items.length;
$items.eq(index).show();
}, delay, $(selector).hide());
}
toggleWithInterval('.container1 > .good', 1000);
toggleWithInterval('.container2 > .good', 300);
/что-то\d+/.$arr = explode(', ', explode('какой-то текст: ', $str)[1]);preg_match_all('/[^ ,:]+(?!.*:)/', $str, $matches);
$arr = $matches[0];
const id = '2'; // а нормальный id придумать было - нет, никак?const el = document.getElementById(id);
// или
const el = document.querySelector(`[id="${id}"]`);
// или (нет, это если бы id нормальный был)
const el = document.querySelector('#' + id);const parent = el.parentNode;.parent.prepend(el);
// или
parent.children[0].before(el);
// или
parent.insertAdjacentElement('afterbegin', el);
// или
parent.insertBefore(el, parent.firstElementChild);
display, кроме none и block? Я вот слышал, будто есть ещё table-cell, например.
var i на let i.document.querySelectorAll('li').forEach((n, i) => {
n.addEventListener('click', e => {
console.log(i);
});
});const onClick = e => console.log(e.target.dataset.index);
const li = document.getElementsByTagName('li');
for (let i = 0; i < li.length; i++) {
li[i].dataset.index = i;
li[i].addEventListener('click', onClick);
}document.querySelector('ul').addEventListener('click', e => {
if (e.target.tagName === 'LI') {
const i = [...e.currentTarget.children].indexOf(e.target);
console.log(i);
}
});
elem.style.opacity += 0.02;elem.style.opacity = (+elem.style.opacity + 0.02).toFixed(2);
.q - а они друг другу соседями не приходятся, поскольку у каждого есть отдельный родительский элемент .trigger. Так что замените $(this).siblings() на $(this).parent().siblings().const $q = $('.trigger .q').click(function() {
$q.not(this).next().slideUp();
$(this).next().slideToggle();
});
watch: {
town_id(val) {
// ну а тут ваш запрос
}
}
resultGenes() {
return this.filteredResultGenes.filter(elem => {
return elem.snps.every(n => n.snpgroup.every(m => m.group_id === 1));
});
}есть похожая задача, только мне необходимо сравнить два значения и если true то отрисовать блок. Every, как я понял возвращает лишь true или false. А есть какой-то метод, чтобы можно было в директиве v-if в массиве пройтись по всем объектам этого массива? ну т.е.
я хочу, чтобы сработала конструкция: v-if="type.id == date.activities.type_id " вот только activities может либо вообще не быть, либо быть пустым либо несколько их может быть.
v-if. Сделайте вычисляемое свойство, которое будет представлять данные, соответствующие условию, и выводите их все.
const obj = Object.assign({}, ...arr.map((n, i) => ({ [n]: arr2[i] })));
// или
const obj = arr.reduce((acc, n, i) => ({ ...acc, [n]: arr2[i] }), {});const combine = (keys, values) =>
keys.reduce((acc, n, i) => (acc[n] = values[i], acc), {});
const obj = combine(arr, arr2);