const getNested = (root, path) => path.split('.').reduce((p, c) => p != null ? p[c] : p, root);
const id = getNested(e, 'path.1.attributes.uid.textContent');
// можно немного сократить функцию извлечения вложенных значений
const getNested = (root, path) => path.split('.').reduce((p, c) => p?.[c], root);
// а можно и вообще отказаться от этой функции, смысла в ней теперь немного
const id = e?.path?.[1]?.attributes?.uid?.textContent;
zoom(change) {
this.map.setZoom(this.map.getZoom() + change);
},
<div @click="zoom(+1)">zoom in</div>
<div @click="zoom(-1)">zoom out</div>
function handler(e) {
console.log('hello, world!!');
this.removeEventListener(e.type, handler);
}
document.addEventListener('click', handler);
document.addEventListener('click', handler, { once: true });
@click="$emit('remove')"
.@remove="removeFromBasket(item)"
. computed: {
declarantKind() {
return this.dsec.reduce((acc, n) => (
acc[n.dsec_nnn] = n.dsec_declarant_kind,
acc
), {});
},
},
watch: {
declarantKind(newVal, oldVal) {
const [ key ] = Object
.entries(newVal)
.find(([ k, v ]) => oldVal.hasOwnProperty(k) && oldVal[k] !== v) || [];
if (key) {
const item = this.dsec.find(n => n.dsec_nnn === key);
console.log('объект:', item);
console.log(`было: ${oldVal[key]}`);
console.log(`стало: ${newVal[key]}`);
}
},
},
modals.entries() судя по документации должен предоставить [key, value]
[...modals.entries()].map(([ id, modal ]) => (
))
data: () => ({
selected: null,
items: [
{ title: 'hello, world!!', value: '' },
{ title: 'fuck the world', value: '' },
{ title: 'fuck everything', value: '' },
],
}),
<div v-for="n in items">
<label>
<input type="radio" :value="n.title" v-model="selected">
{{ n.title }}
</label>
<input type="text" v-model="n.value" :disabled="selected !== n.title">
</div>
const result = arr.reduce((acc, n, i) => {
if (здесь вы проверяете элемент массива на соответствие своему условию) {
let group = acc[acc.length - 1];
if (!group || group.index !== i - 1) {
group = { data: [] };
acc.push(group);
}
group.index = i;
group.data.push(n);
}
return acc;
}, []).map(n => n.data);
.fade-leave-active {
transition: opacity 1s;
}
.fade-leave-to {
opacity: 0;
}
mounted() {
this.show = false;
},
phone.value = phone.value.replace(/[^+0-9]/g, '').slice(0, 11);
const canvas = document.querySelector('#canvas');
const ctx = canvas.getContext('2d');
const TILE_SIDE = 32;
let pickX = 0;
let pickY = 0;
const ground = new Image();
ground.src = 'Ground.png';
const pick = new Image();
pick.src = 'Pick.png';
document.addEventListener('keydown', function(e) {
switch (e.key) {
case 'w': pickY -= TILE_SIDE; break;
case 'a': pickX -= TILE_SIDE; break;
case 's': pickY += TILE_SIDE; break;
case 'd': pickX += TILE_SIDE; break;
default: return;
}
draw();
});
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let x = 0; x < canvas.width; x += TILE_SIDE) {
for (let y = 0; y < canvas.height; y += TILE_SIDE) {
ctx.drawImage(ground, x, y);
}
}
ctx.drawImage(pick, pickX, pickY);
}
draw();