если я ставлю параметр :interval="100", то у меня появляется черная полоса под слайдером и все начинает очень лагать
methods: {
marks: v => !(v % 20000),
...<vue-slider
:marks="marks"
...
const containerSelector = '.block-btn';
const itemSelector = `${containerSelector} [data-cost]`;
const activeClass = 'active';const onClick = ({ currentTarget: t }) => t
.closest(containerSelector)
.querySelectorAll(itemSelector)
.forEach(n => n.classList.toggle(activeClass, n === t));
document.querySelectorAll(itemSelector).forEach(n => {
n.addEventListener('click', onClick);
});for (const n of document.querySelectorAll(containerSelector)) {
n.addEventListener('click', onClick);
}
function onClick(e) {
const item = e.target.closest(itemSelector);
if (item) {
this.querySelector(`.${activeClass}`)?.classList.remove(activeClass);
item.classList.add(activeClass);
}
}document.addEventListener('click', ({ target: t }) => t
.closest(itemSelector)
?.closest(containerSelector)
.querySelectorAll(itemSelector)
.forEach(n => n.classList.toggle(activeClass, n.contains(t)))
);
const [ items, setItems ] = useState([
{ id: ..., text: '...', active: false },
{ id: ..., text: '...', active: false },
...
]);const reset = () => setItems(items.map(n => ({ ...n, active: false })));<button onClick={reset}>reset</button>const toggle = id => setItems(items.map(n => n.id === id ? { ...n, active: !n.active } : n));{items.map(n => <Text key={n.id} {...n} toggle={toggle} />)}const Text = ({ id, text, active, toggle }) => (
<p
className={active ? 'active' : ''}
onClick={() => toggle(id)}
>
{text}
</p>
);
Понимаю, что это как-то связано с преждевременным размонтированием компонента перед завершением api запроса.
<apexchart
ref="chart"
...mounted() {
this.$nextTick(() => {
this.$refs.chart.hideSeries('здесь имя набора данных, который не хотите показывать');
});
},
const delimiter = str.match(/\D/)[0];
// или
const delimiter = str[str.search(/\D/)];
// или
const [ delimiter ] = str.replace(/^\d+/, '');
// или
const delimiter = Array.prototype.find.call(str, n => Number.isNaN(+n));
// или
const delimiter = [...str].filter(n => !'0123456789'.includes(n)).shift();
const parent = document.querySelector('.container');
const className = 'green';
const startFrom = 4;parent
.querySelectorAll(`:scope > :nth-child(n + ${startFrom + 1})`)
.forEach(n => n.classList.add(className));
// или
for (const n of Array.prototype.slice.call(parent.children, startFrom)) {
n.classList.add(className);
}
// или
for (let el = parent.children[startFrom]; el; el = el.nextElementSibling) {
el.classList.add(className);
}
// или, также удаляем класс (если вдруг есть) у тех, кому он не должен быть добавлен
for (let i = 0; i < parent.children.length; i++) {
parent.children[i].classList.toggle(className, i >= startFrom);
}
function createRandomArr(size, min, max) {
if (size > (max -= ~-min)) {
throw 'невозможно создать массив указанного размера';
}
const values = new Set;
for (; values.size < size; values.add(min + Math.random() * max | 0)) ;
return [...values];
}function createRandomArr(size, min, max) {
const len = max - min + 1;
const arr = [...Array(len).keys()];
return Array.from(
{ length: Math.min(size, len) },
() => min + arr.splice(Math.random() * arr.length | 0, 1)[0]
);
}function createRandomArr(size, min, max) {
const arr = Array.from(
{ length: max - min + 1 },
(_, i) => i + min
);
for (let i = arr.length; --i > 0;) {
const j = Math.floor(Math.random() * (i + 1));
[ arr[j], arr[i] ] = [ arr[i], arr[j] ];
}
return arr.slice(-size);
}
Components can recursively invoke themselves in their own template. However, they can only do so with the name option
const values = [ id, sum, system, date ];.payment.innerHTML = values.map(n => `<td>${n}</td>`).join('');
// или
values.forEach(n => payment.insertCell().textContent = n);
// или
payment.append(...values.map(n => {
const td = document.createElement('td');
td.innerText = n;
return td;
}));- function createPayment({id, sum, system, date}) {
+ function createPayment(data) {- const values = [ id, sum, system, date ];
+ const keys = [ 'id', 'sum', 'system', 'date' ];- values.forEach(n => payment.insertCell().textContent = n);
+ keys.forEach(n => payment.insertCell().textContent = data[n]);
мне ж понятно будет
const getKeys = obj =>
obj instanceof Object
? Object.entries(obj).flatMap(n => [ n[0], ...getKeys(n[1]) ])
: [];
const keys = getKeys(obj);function* getKeys(obj) {
if (Object(obj) === obj) {
for (const k in obj) if (obj.hasOwnProperty(k)) {
yield k;
yield* getKeys(obj[k]);
}
}
}
const keys = [...getKeys(obj)];
const propsCount = 3;.const newObj = Object.fromEntries(Object
.entries(obj)
.sort((a, b) => a[1] - b[1])
.slice(-propsCount)
);Object
.entries(obj)
.sort((a, b) => b[1] - a[1])
.slice(propsCount)
.forEach(n => delete obj[n[0]]);
watch: {
данные: {
immediate: true,
handler(value) {
if (value какой нужен) {
делаете чего там вам надо
}
},
},
},computed: {
данные() {
return [ this.данные1, this.данные2, /* ... */ ];
},
},
watch: {
данные: {
immediate: true,
handler(value) {
if (value.every(n => n какой нужен)) {
делаете чего там вам надо
}
},
},
},