data: () => ({
size: 52,
col: 0,
row: 0,
}),
methods: {
onMouseMove(e) {
this.col = e.offsetX / this.size | 0;
this.row = e.offsetY / this.size | 0;
},
},
computed: {
blockStyle() {
return {
backgroundSize: `${this.size}px ${this.size}px`,
};
},
blockCursorStyle() {
const { col, row, size } = this;
return {
transform: `translate(${col * size}px, ${row * size}px)`,
width: `${size * 0.95}px`,
height: `${size * 0.95}px`,
};
},
},
<div class="block" :style="blockStyle" @mousemove="onMouseMove">
<div class="block-cursor" :style="blockCursorStyle"></div>
</div>
margin-top: $margin;
@for $i from 1 through $count {
&:nth-child(#{$i}) {
margin-top: 0;
}
}
interface ItempElement {
x: number;
y: number;
};
interface Itemp extends Array<ItempElement> {};
В документации не нашёл.
const values = arr.length
? arr[0].filter(n => arr.every(m => m.includes(n)))
: [];
const values = (arr[0] || []).filter(function(n) {
return this.every(m => m.has(n));
}, arr.map(n => new Set(n)));
const values = Array
.from(arr
.flatMap(n => [...new Set(n)])
.reduce((acc, n) => acc.set(n, (acc.get(n) || 0) + 1), new Map))
.reduce((acc, n) => ((n[1] === arr.length) && acc.push(n[0]), acc), []);
const values = Array
.from(arr.reduce((acc, n) => (
n.forEach(m => acc.set(m, acc.get(m) || new Set).get(m).add(n)),
acc
), new Map))
.reduce((acc, n) => (n[1].size === arr.length && acc.push(n[0]), acc), []);
const values = [...arr.reduce((acc, n) => (
n = new Set(n),
acc.intersection?.(n) ?? n
), [])];
Vue.directive('сarusel', {
<select id="country"></select>
<select id="city"></select>
const countryEl = document.querySelector('#country');
const cityEl = document.querySelector('#city');
countryEl.innerHTML = data.map(n => `<option value="${n.id}">${n.country}</option>`).join('');
countryEl.addEventListener('change', function() {
cityEl.innerHTML = data
.find(n => n.id === this.value)
.cities
.map(n => `<option value="${n.id}">${n.city}</option>`)
.join('');
});
countryEl.dispatchEvent(new Event('change'));
ругается на сайд эффект, что я в рэндере меняю состояние массива
answers={shuffleArray(currentQuestion.answers)}
answers={shuffleArray([...currentQuestion.answers])}
return this.singleMetricNamesMap.forEach(el => el[this.value.metricId])
metric() { if (this.metric) { this.setSingleMetricNamesMap({ [this.metric.id]: this.metric.name }) } }
this.
не нужен:metric(val) {
if (val) {
this.setSingleMetricNamesMap({ [val.id]: val.name });
}
},
const N = чему-то там равно;
for (let i = 1, num = 1; i <= N; i++) {
console.log(num);
if (i === (1 + num) * num / 2) {
num++;
}
}
for (let i = 1; i <= N; i++) {
console.log(Math.ceil((Math.sqrt(1 + 8 * i) - 1) / 2));
}
<v-data-table>
<template #item="{ item }">
<tr>
<td class="какой-то_класс">{{ item['какое-то свойство'] }}</td>
<td class="ещё_какой-то_класс">{{ item['ещё какое-то свойство'] }}</td>
<td class="ну_и_так_далее">{{ item['как видите, ничего сложного'] }}</td>
</tr>
</template>
</v-data-table>
const last = promises => new Promise((resolve, reject) => {
let pending = promises.length;
if (!pending) {
resolve();
} else {
promises.forEach(n => n
.then(result => --pending || resolve(result))
.catch(error => --pending || reject(error))
);
}
});
v-for={weekDay in this.arWeekDays}
выдает ошибку "index is not defined"
<div>
{this.arWeekDays.map(n => <div>{n}</div>)}
</div>
siteForm.userAdmin = loginValue === login && passwordValue === password;
const order = Object.fromEntries(gameTypeOrder.map((n, i) => [ n, i ]));
res.sort((a, b) => order[a.game_status] - order[b.game_status]);
const sortedRes = res
.reduce((acc, n) => (acc[order[n.game_status]].push(n), acc), gameTypeOrder.map(() => []))
.flat();
// или
const sorted = (arr, key) => arr
.map(n => [ n, key(n) ])
.sort((a, b) => a[1] - b[1])
.map(n => n[0]);
const sortedRes = sorted(res, n => order[n.game_status]);