props: { user: String }, emits: ["update:someUser"]
- emits: ["update:someUser"]
+ emits: ["update:user"]
- @input="$emit('update:someUser', $event.target.value)"
+ @input="$emit('update:user', $event.target.value)"
const sumIntervals = intervals => intervals
.slice()
.sort((a, b) => a[0] - b[0])
.reduce((acc, n) => {
const top = acc.at(-1);
if (!top || top[1] < n[0]) {
acc.push([...n]);
} else if (top[1] < n[1]) {
top[1] = n[1];
}
return acc;
}, [])
.reduce((acc, n) => acc - n[0] + n[1], 0);
$('.container').prepend(function() {
return $('.wrapper-item h3', this);
});
document.querySelectorAll('.wrapper-item h3').forEach(n => {
n.closest('.container').prepend(n);
});
data: () => ({
items: [
{ text: '69', tooltip: 'hello, world!!' },
{ text: '187', tooltip: 'fuck the world' },
{ text: '666', tooltip: 'fuck everything' },
],
}),
<div
v-for="n in items"
v-text="n.text"
:data-tooltip="n.tooltip"
class="item"
></div>
.item {
display: inline-flex;
justify-content: center;
align-items: center;
color: white;
background: red;
width: 150px;
height: 50px;
margin: 10px;
position: relative;
}
.item:hover::before {
content: attr(data-tooltip);
display: inline-block;
background: blue;
color: white;
position: absolute;
}
computed: {
filteredWorks() {
const category = this.tabs.find(n => n.id === this.activeTabId)?.category;
return category равна той, что у 'Все работы'
? this.works
: this.works.filter(n => n.category === category);
},
<div class="articles__items articles__items--works">
<img v-for="n in filteredWorks" :key="n.id" :src="n.image">
</div>
tabs: [ { id: '1', name: 'Все работы', category: 'doors' }, { id: '2', name: 'Окна', category: 'windows' }, { id: '3', name: 'Двери', category: 'doors' },
props: { spawns: Boolean
data() { return { play: false, active: false, prepare: false, spawns: {
<div class="hr">
<div class="logo">
<div class="icon">
const classes = {
Class1: class {
constructor(val) {
this.val = val;
}
method1() {
console.log('Class1', this.val);
}
},
Class2: class {
constructor(val1, val2) {
this.val1 = val1;
this.val2 = val2;
}
method2() {
console.log('Class2', this.val1, this.val2);
}
},
};
function createInstanceAddCallMethod(className, constructorParams, methodName) {
const instance = new classes[className](...constructorParams);
instance[methodName]();
}
createInstanceAddCallMethod('Class1', [ 69 ], 'method1');
createInstanceAddCallMethod('Class2', [ 187, 666 ], 'method2');
$grouped = array_map(function($n) {
for ($i = 1; $i < count($n); $i++) {
$min = min($n[$i]);
$max = max($n[$i]);
$n[$i] = ($min === $max) ? $min : "$min-$max";
}
return $n;
}, array_values(array_reduce($arr, function($acc, $n) {
$acc[$n[0]] ??= [ $n[0] ];
for ($i = 1; $i < count($n); $i++) {
$acc[$n[0]][$i][] = $n[$i];
}
return $acc;
}, [])));
const flat = (arr, childrenKey = 'children') =>
(arr instanceof Array ? arr : []).reduce((acc, n) => (
acc.push(n, ...flat(n[childrenKey], childrenKey)),
acc
), []);
// или, если нужны копии объектов без ссылок на массивы вложенных объектов:
const flat = (arr, childrenKey = 'children') =>
Array.isArray(arr)
? arr.flatMap(({ [childrenKey]: c, ...n }) => [
n,
...flat(c, childrenKey),
])
: [];
v-for
по его значению:computed: {
users() {
return flat(this.elements);
},
},
<option v-for="n in users" :key="n.id">{{ n.name }}</option>
<gmap-map
ref="map"
...
const bounds = new google.maps.LatLngBounds();
массивКоординатВашихЛокаций.forEach(n => bounds.extend(n));
this.$refs.map.fitBounds(bounds);
const result = a.map(function(n) {
return b.slice(this[0], this[0] += n).reduce((acc, n) => acc * n, 1);
}, [ 0 ]);
const result = a.map(n => b.splice(0, n).reduce((acc, n) => acc * n, 1));
const mostFrequentNum = Array
.from(arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map))
.reduce((max, n) => max[1] > n[1] ? max : n, [ , 0 ])[0];
const mostFrequentNum = Object
.entries(arr.reduce((acc, n) => (acc[n] = (acc[n] ?? 0) + 1, acc), {}))
.reduce((acc, n) => (acc[n[1]] = +n[0], acc), [])
.pop();
не хочу дублировать код в v-slot:fastFilters, но как мне сделать так, чтоб по определенному флагу на фильтрах он появлялся и в fastFilters
<toolbar>
<slot name="fastFilters">
<slot name="filters" v-if="а здесь ваш флаг">
</toolbar>
<div class="filters">
<slot name="filters">
</div>