v-for="area in `${ this.$route.params.type }Areas`"
v-for="area in this[`${$route.params.type}Areas`]"
разве vue не повсеместно лишает возможности мутировать данные родителя в потомках?
как вообще так вышло, что v-model внизу сумел изменить serviceBlocksBlocks
const average = arr => arr.reduce((acc, n) => acc + n, 0) / arr.length;
const extractValues = (group, item, key) => item[key].forEach(n => ((group.values[n.id] ||= { id: n.id, name: n.name })[key] ||= []).push(n.value));
const result = Object
.values(arr
.flatMap(n => n.properties.groups)
.reduce((acc, n) => (
acc[n.id] ||= {
id: n.id,
name: n.name,
wellBeing: [],
values: {},
},
acc[n.id].wellBeing.push(n['well-being']),
extractValues(acc[n.id], n, 'needs'),
extractValues(acc[n.id], n, 'provision'),
acc
), {}))
.map(n => ({
id: n.id,
name: n.name,
value: average(n.wellBeing),
values: Object.values(n.values).map(m => (
m.needs = average(m.needs),
m.provision = average(m.provision),
m
))
}));
const xxx = ([...str]) => [...new Set(Array.from(
{ length: str.length * 10 },
(n, i) => str.map((m, j) => (j === (i / 10 | 0)) ? i % 10 : m).join('')
))];
function xxx(str) {
const arr = str.split('');
const result = [ str ];
for (const [ i, n ] of arr.entries()) {
for (let j = 0; j < 10; j++) {
if (j !== +n) {
arr[i] = j;
result.push(arr.join(''));
}
}
arr[i] = n;
}
return result;
}
data: () => ({
items: [ 1, 25, 32, 4, 5 ],
filter: false,
}),
computed: {
filteredItems() {
return this.items.filter(n => n < 10);
},
},
<label>
<input type="checkbox" v-model="filter">
Фильтровать
</label>
<ul>
<li v-for="n in (filter ? filteredItems : items)">{{ n }}</li>
</ul>
Я не меняю prop href
@Prop(String) href = '';
It's not supported to define eachdefault
property like@Prop() prop = 'default value'
.
const first = document.querySelector('#first');
const second = document.querySelector('#second');
const showOptions = {
1: [ '1', '11', '16' ],
2: [ '12', '14', '15' ],
};
first.addEventListener('change', function() {
const toShow = showOptions[this.value];
[...second].forEach(n => n.hidden = +n.value && toShow && !toShow.includes(n.value));
});
const nav = document.querySelector('.nav');
const itemSelector = '.nav-link';
const image = document.querySelector('.preview-img');
const category = document.querySelector('.preview-head');
function updatePreview(data) {
image.src = data.img;
category.textContent = data.category;
}
nav.querySelectorAll(itemSelector).forEach(function(n) {
n.addEventListener('mouseenter', this);
}, e => updatePreview(e.target.dataset));
nav.addEventListener('mouseover', e => {
const data = e.target.closest(itemSelector)?.dataset;
if (data) {
updatePreview(data);
}
});
metricsColumn: true
.computed: {
metricsColumns() {
return this.headers.filter(n => n.metricsColumn);
},
},
<template
v-for="(n, i) in metricsColumns"
#[`item.${n.value}`]="{ item: { metrics: { [i]: item } } }"
>
<v-chip
:color="colors[item.metricsValueMarkName]"
:key="n.value"
dark
>
{{ item.metricsValue }}
</v-chip>
</template>
function output(value) {
const digits = document.querySelectorAll('селектор span`ов');
const { length } = digits;
Array
.from(`${value}`.padStart(length, 0).slice(-length))
.forEach((n, i) => digits[i].innerText = n);
}
function output(value) {
document.querySelector('селектор родительского элемента span`ов').innerHTML = Array
.from(`${value}`, n => `<span>${n}</span>`)
.join('');
}
const [ first, ...rest ] = document.querySelectorAll('[type="checkbox"]');
const onChange = () => first.checked = rest.every(n => n.checked);
first.addEventListener('change', () => rest.forEach(n => n.checked = first.checked));
rest.forEach(n => n.addEventListener('change', onChange));
img
:const { images } = new DOMParser().parseFromString(html, 'text/html');
// или
const images = document
.createRange()
.createContextualFragment(html)
.querySelectorAll('img');
// или
const images =
(el => (el.innerHTML = html, el.getElementsByTagName('img')))
(document.createElement('div'));
img
извлечь значения src
и srcset
:const getSrc = img => [ img.src, img.srcset ];
// или
const getSrc = img => [ 'src', 'srcset' ].map(n => img.getAttribute(n));
// или
const getSrc = ({ attributes: a }) => [ a.src.value, a.srcset.value ];
const result = Array.from(images, getSrc);
// или
const result = Array.prototype.map.call(images, getSrc);
// или
const result = [];
for (const n of images) {
result.push(getSrc(n));
}
// или
const result = [];
for (let i = 0; i < images.length; i++) {
result[i] = getSrc(images.item(i));
}
// или
const result = (function get(i) {
return images[i] ? [ getSrc(images[i]), ...get(i + 1) ] : [];
})(0);
const parent = document.querySelector('селектор элемента, из которого надо кого-то удалить');
const toRemove = [ 3, 1, 666, 2 ];
toRemove
.map(n => parent.children[n])
.filter(Boolean)
.forEach(n => n.remove());
// или
toRemove
.sort((a, b) => b - a)
.forEach(n => parent.children[n]?.remove());
// или
[...parent.children].forEach((n, i) => toRemove.includes(i) && n.remove());
:style="mapStyles"
data() { return { mapStyles: { styles: [
mapStyles: {
на options: {
:style="mapStyles"
на :options="options"
data: () => ({
contact: '',
}),
methods: {
onClick() {
if (this.contact) {
this.$emit('close');
}
},
},
<input v-model="contact">
<button @click="onClick">
const getStrs = (arrs, len) => [
'*'.repeat(len + 2),
...arrs.flatMap(arr => arr
.reduce((acc, n) => {
let g = acc[acc.length - 1];
(g && (g[1] + n.length + !!g[0].length) <= len) || acc.push(g = [ [], 0 ]);
g[1] += n.length + !!g[0].length;
g[0].push(n);
return acc;
}, [])
.map((n, i, a) => `*${n[0].join(' ')[a.length > 1 ? 'padStart' : 'padEnd'](len, ' ')}*`)),
'*'.repeat(len + 2),
];
console.log(getStrs(textArray, 16));