data: () => ({
value: '',
values: [ 'hello, world!!', 'fuck the world', 'fuck everything' ],
}),
<input v-model="value">
<button v-for="(n, i) in values" @click="value = n">set value #{{ i + 1 }}</button>
data: () => ({
scroll: 0,
}),
computed: {
style() {
return {
height: здесь рассчитываете высоту на основе this.scroll,
};
},
},
created() {
const onScroll = () => this.scroll = document.scrollingElement.scrollTop;
onScroll();
document.addEventListener('scroll', onScroll);
this.$on('hook:beforeDestroy', () => document.removeEventListener('scroll', onScroll));
},
<div :style="style">
const options = [
[ 'hello, world!!', 'fuck the world', 'fuck everything' ],
500,
console.log,
];
function interval(arr, delay, callback) {
let i = -1;
return arr.length
? setInterval(() => callback(arr[i = -~i % arr.length]), delay)
: null;
}
const intervalId = interval(...options);
// надо остановить хождение по кругу, делаем так: clearInterval(intervalId);
function interval(arr, delay, callback) {
let timeoutId = null;
arr.length && (function step(i) {
timeoutId = setTimeout(() => {
callback(arr[i]);
step((i + 1) % arr.length);
}, delay);
})(0);
return () => clearTimeout(timeoutId);
}
const stop = interval.apply(null, options);
// надо остановить, делаем так: stop();
computed: {
grouped() {
return this.dataTable.reduce((acc, n) => {
(acc[n.customer.name] = acc[n.customer.name] ?? []).push(n);
return acc;
}, {});
},
},
<template v-for="(items, customer) in grouped">
<tr>
...
</tr>
<tr v-for="item in items">
...
</tr>
</template>
function xxx(key) {
let val = entityTree[key];
const nextKey = Array.isArray(val) && (val = [...val], val.pop());
return val ? [].concat(key, val, xxx(nextKey)) : [];
}
v-for="image in images"
должно быть v-for="image in result.images"
.v-model="profileImg"
и {{profileImg}}
должно быть v-model="result.profileImg"
и {{ result.profileImg }}
.name="profileImg"
значение name должно вычисляться динамически, в зависимости от result (например - добавляйте id, если есть, или индекс).<li>{{ result.sizes.join(' ') }}</li>
должно быть <li v-for="size in result.sizes">{{ size }}</li>
. if (obj.hasOwnProperty(key)) {
if (!Array.isArray(obj[key])) {
obj[key] = [ obj[key] ];
}
obj[key].push(val);
} else {
obj[key] = val;
}
это для массива, а у меня объект
Array.isArray
проверяйте instanceof Object
. А ключ нового свойства - это количество уже существующих свойств:if (obj.hasOwnProperty(key)) {
if (!(obj[key] instanceof Object)) {
obj[key] = { 0: obj[key] };
}
obj[key][Object.keys(obj[key]).length] = val;
} else {
obj[key] = val;
}
for (let i = times.length; i--;) {
const d = new Date(times[i]);
if (d <= date) {
result.children[i].classList.add('active');
result.children[i + 1]?.classList.add('next');
break;
}
}
users.filter(u => u.services.some(s => filterBy.every(f => s.categories.includes(f))))
users.filter(u => filterBy.every(f => u.services.some(s => s.categories.includes(f))))
users.filter(u => filterBy.some(f => u.services.some(s => s.categories.includes(f))))
$('.products').append(data.uslugi.map(item => `
<div class="item p-2">
<img src="${item.img}" alt="" class="p-2 h-64 mx-auto">
<h2 class="text-lg text-center font-semibold p-1 pb-0">${item.title}</h2>
<div class="flex flex-wrap w-56 mx-auto py-2 pt-0 text-lg sizes">
${item.size.map(size => `
<div class="p-1 flex size">
<span class="px-2 rounded-full size active">${size}</span>
</div>
`).join('')}
</div>
</div>
`).join(''))
case 'BASKET':
return {
...state,
products: state.products.map(n => n.name === action.payload
? { ...n, basket: true }
: n
),
};
onPress={() => this.props.addToBasket.bind(this, this.props.product.name)}
onPress={() => this.props.addToBasket(this.props.product.name)}
const showProductsList = (type, maxlength) => { <...> if(product.basket == type & currentLength < maxlength) {
showProductsList("true", 4)
true
не будет равно "true"
, убираем кавычки: showProductsList(true, 4)
.const form = document.querySelector('.form');
const items = [...form.querySelectorAll('.form__item')];
form.addEventListener('change', function(e) {
const index = items.indexOf(e.target.closest('.form__item'));
form.querySelector('.form__progress-line').style.width = (index + 2) * 100 / items.length + '%';
setTimeout(() => {
items[index]?.classList.remove('form__item--active');
items[index + 1]?.classList.add('form__item--active');
if (index + 1 === items.length) {
form.style.display = 'none';
document.querySelector('.result').classList.add('result--active');
}
}, 1000);
});
form.dispatchEvent(new Event('change'));