getOneProfile: state => { return state.profile }
{{ getOneProfile.profile.name }}
state.profile
есть свойство profile
? Типа, можно было бы и $store.state.profile.profile.name
написать? Подозреваю, что profile
всё-таки лишний. Ну и чтобы не пытаться выводить данные, которых пока нет, используйте условный рендеринг:<КакойТоКомпонент v-if="данные">
Я думал, нужно делать какой то лоадер, пока данные идут?
<КакойТоКомпонент v-if="данные" />
<ИндикаторЗагрузки v-else />
const table = document.querySelector('.table-price table');
.highlight-min {
color: green;
font-weight: bold;
}
.highlight-max {
color: red;
font-weight: bold;
}
table.querySelectorAll('tr').forEach(n => {
const td = Array
.from(n.querySelectorAll('td:not(.logo-table)'), m => [ m, +m.innerText.match(/\d+/) ])
.sort((a, b) => a[1] - b[1])[0][0];
td.classList.add('highlight-min');
});
for (const { cells: [ , ...cells ] } of table.rows) {
const [ tds ] = cells.reduce((max, n) => {
const val = parseInt(n.textContent);
if (val > max[1]) {
max = [ [], val ];
}
if (val === max[1]) {
max[0].push(n);
}
return max;
}, [ [], -Infinity ]);
tds.forEach(n => n.classList.add('highlight-max'));
}
Первое, что нужно знать — store.dispatch
может обрабатывать Promise, возвращаемый обработчиком действия, и также возвращает Promise
computed: {
catId() {
return this.$route.meta.catId;
},
},
<ListProducts :catId="$route.meta.catId" />
@click="checkOption(option);"
v-model
is required
domProps: {
value: this.value,
},
const className = 'класс элементов, чьи id вам надо получить';
const elems = document.querySelectorAll(`.${className}`);
// или
const elems = document.getElementsByClassName(className);
const getId = el => el.id;
// или
const getId = el => el.getAttribute('id');
// или
const getId = el => el.attributes.id.value;
const ids = Array.from(elems, getId);
// или
const ids = Array.prototype.map.call(elems, getId);
// или
const ids = [];
for (const n of elems) {
ids.push(getId(n));
}
// или
const ids = [];
for (let i = 0; i < elems.length; i++) {
ids[i] = getId(elems[i]);
}
// или
const ids = (function get(i, n = elems.item(i)) {
return n ? [ getId(n), ...get(i + 1) ] : [];
})(0);
v-model="selectField[index]"
заменяете на v-model="item.value"
, например, а selectField.includes(name)
на conditionList.some(n => n.value === name)
. бибилиотека react-yandex-maps не имеет такой функциональности
const result = Object.values(arr.reduce((acc, n) => (
acc[n.id] = n.checked ? n : (acc[n.id] || n),
acc
), {}));
const result = arr.reduce((acc, n) => {
const i = acc.findIndex(m => m.id === n.id);
if (!~i || (!acc[i].checked && n.checked)) {
acc.push(n);
if (~i) {
acc.splice(i, 1);
}
}
return acc;
}, []);
// или
const result = Object
.values(arr.reduce((acc, n, i) => (
(!acc[n.id] || (!acc[n.id][0].checked && n.checked)) && (acc[n.id] = [ n, i ]),
acc
), {}))
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
[...document.querySelectorAll('.buy > i')]
.filter((n, i, a) => i !== a.findIndex(m => m.innerText === n.innerText))
.forEach(n => n.parentNode.style.display = 'none');
const grouped = Array
.from(document.querySelectorAll('.buy > i'), n => [ n.parentNode, n.innerText ])
.reduce((acc, n) => ((acc[n[1]] = acc[n[1]] || []).push(n[0]), acc), {});
Object.values(grouped).forEach(n => n.forEach((m, i) => m.hidden = !!i));
.hidden {
display: none;
}
const unique = new Set();
for (const n of document.querySelectorAll('.buy > i')) {
if (unique.has(n.innerText)) {
n.parentNode.classList.add('hidden');
} else {
unique.add(n.innerText);
}
}
people.filter((n, i, a) => n.country && i === a.findIndex(m => m.country === n.country))
people.filter(n => n.country && n === people.find(m => m.country === n.country))
people.filter(function({ country: n }) {
return n && !(this[n] = this.hasOwnProperty(n));
}, {})
Object.values(people.reduce((acc, n) => (n.country && (acc[n.country] = n), acc), {}))
[...people.reduce((acc, n) => n.country ? acc.set(n.country, n) : acc, new Map).values()]
Array.from(
new Set(people.map(n => n.country).filter(Boolean)),
n => people.find(m => m.country === n)
)
const block = document.querySelector('.block');
const inputSelector = 'input[type="number"]';
const toggleBlock = () =>
block.style.display = Array
.from(document.querySelectorAll(inputSelector))
.some(n => n.value && +n.value > +n.min)
? 'block'
: 'none';
document.addEventListener('input', e => e.target.matches(inputSelector) && toggleBlock());
toggleBlock();
// или
const inputs = document.querySelectorAll(inputSelector);
const toggleBlock = () =>
block.hidden = Array.prototype.every.call(
inputs,
n => !n.value || +n.value <= +n.min
);
inputs.forEach(n => n.addEventListener('input', toggleBlock));
toggleBlock();
if ( typeof arr[i] === 'number' ) { x*= arr[i];
arr[i + 1]
окажется строкой? Сначала надо проверить всё, а уже потом вычислять (если потребуется) объединённое значение:function bullshit(arr) {
if (arr.every(n => typeof n === 'number')) {
return arr.reduce((acc, n) => acc * n, 1);
}
if (arr.every(n => typeof n === 'string')) {
return arr.join('');
}
return null;
}
bullshit([ 1, 2, 3 ]) // 6
bullshit([ 'a', 'b', 'c' ]) // 'abc'
bullshit([ 1, '!' ]) // null
function bullshit(arr) {
const count = arr.reduce((acc, n) => {
const type = typeof n;
acc[type] = (acc[type] || 0) + 1;
return acc;
}, {});
switch (arr.length) {
case count.number: return arr.reduce((acc, n) => acc * n, 1);
case count.string: return arr.join('');
default: return null;
}
}