Насколько хороши варианты:
1. интервалом синхронить стейт корзины.
2. Синхронить стейт при событии onunload
3. Писать обработчик кликов, который будет регулировать частоту запросов (очень не хочется)
methods: {
syncCart: debounce(function() {
...
}),
},
watch: {
'$store.state.cart': {
immediate: true,
deep: true,
handler: 'syncCart',
},
},
$("#box1:checked, #box2:checked").val()
$('#logistic input:checked').get().reduce((acc, n) => acc + +n.value, 0)
function GetCookies(name) { <...> return null; } <...> faves.push(fav); <...> var myfaves = JSON.parse(GetCookies('favespages')); faves = myfaves;
faves = myfaves instanceof Array ? myfaves : [];
. data: () => ({
items: [
{ раз_свойство: '', два_свойство: '', три_свойство: '', ... },
...
],
}),
<table>
<tbody>
<tr v-for="(n, i) in items">
<td>#{{ i + 1 }}</td>
<td v-for="(v, k) in n">
{{ k }}:
<input v-model="n[k]">
</td>
</tr>
</tbody>
</table>
const result = tags.filter(n => active.some(m => m.name === n.name));
const result = tags.filter(function(n) {
return this.has(n.name);
}, new Set(active.map(n => n.name)));
const tagsObj = tags.reduce((acc, n) => (acc[n.name] = n, acc), {});
const result = active.reduce((acc, n) => ((n = tagsObj[n.name]) && acc.push(n), acc), []);
$('.photo-link').val(function() {
return $(this).parent().find('.ulightbox').attr('href');
});
document.querySelectorAll('.photo-link').forEach(n => {
n.value = n.parentNode.querySelector('.ulightbox').getAttribute('href');
});
$('#btn').click(function() {
i = (i + 1) % arrLatLng.length;
map.setCenter(arrLatLng[i]);
});
return *this
в конце нужных методов. Например:class XXX {
double val;
public:
XXX(double v) {
val = v;
}
XXX& add(double v) {
val += v;
return *this;
}
XXX& sub(double v) {
val -= v;
return *this;
}
friend std::ostream& operator <<(std::ostream &os, const XXX &x) {
return os << x.val;
}
};
...
std::cout << XXX(5).sub(1).add(2).sub(3).add(4) << endl; // 7
const containerSelector = '.info';
const buttonSelector = `${containerSelector} button`;
const props = [ 'quantity', 'square', 'floor' ];
const { elements } = document.querySelector('form');
document.addEventListener('click', ({ target: t }) => {
if (t.matches(buttonSelector)) {
props.forEach(function(n) {
elements[n].value = this.querySelector(`.${n}`).textContent;
}, t.closest(containerSelector));
}
});
const result = arr.flatMap((n, i) => i & 1 ? n : [...n].reverse());
const result = [];
for (let i = 0; i < arr.length; ++i) {
const a = i & 1 ? arr[i] : [...arr[i]].reverse();
for (let j = 0; j < a.length; ++j) {
result.push(a[j]);
}
}
мне как бы очень важна производительность, и reverse() это как бы дополнительная операция
const result = arr.reduce((acc, n, i) => (
i & 1
? acc.push(...n)
: n.reduceRight((_, m) => acc.push(m), null),
acc
), []);
// или
const result = [];
for (const [ i, n ] of arr.entries()) {
const [ start, end, step ] = [
[ n.length, -1, -1 ],
[ -1, n.length, 1 ],
][i & 1];
for (let j = start; (j += step) !== end;) {
result.push(n[j]);
}
}