const buttonSelector = '.added';
const itemSelector = '.added-block';
const activeClass = '_active';
const notActiveSelector = `${itemSelector}:not(.${activeClass})`;
const newActiveCount = 2;
function onButtonClick(button) {
const items = [...button.parentNode.querySelectorAll(notActiveSelector)];
items.slice(0, newActiveCount).forEach(n => n.classList.add(activeClass));
button.disabled = items.length <= newActiveCount;
}
document.querySelectorAll(buttonSelector).forEach(function(n) {
n.addEventListener('click', this);
}, e => onButtonClick(e.currentTarget));
document.addEventListener('click', e => {
const button = e.target.closest(buttonSelector);
if (button) {
onButtonClick(button);
}
});
Thev-enter
transition class has been renamed tov-enter-from
<RatingSelect v-model="rating" />
const props = defineProps({
modelValue: {
type: Number,
required: true,
},
maxRating: {
type: Number,
default: 10,
},
});
const emit = defineEmits([ 'update:modelValue' ]);
const selected = computed({
get: () => props.modelValue,
set: val => emit('update:modelValue', val),
});
<li v-for="n in maxRating">
<label>
<input type="radio" :value="n" v-model="selected">
{{ n }}
</label>
</li>
function App() {
const [ count, setCount ] = useState(() => +localStorage.getItem('count') || 0);
useEffect(() => {
localStorage.setItem('count', count);
}, [ count ]);
const onClick = e => setCount(count => count + +e.target.dataset.change);
return (
<div>
<h1>Count: {count}</h1>
<button onClick={onClick} data-change="+1">+</button>
<button onClick={onClick} data-change="-1">-</button>
</div>
);
}
data: () => ({
buttons: [
{ className: 'btn1', text: 'Limit' },
{ className: 'btn2', text: 'Market' },
],
active: 0,
}),
<button
v-for="(n, i) in buttons"
v-text="n.text"
:class="[ 'btn', n.className, { 'active-btn': i === active } ]"
@click="active = i"
></button>
btn*
действительно идут по порядку)data: () => ({
buttons: [ 'Limit', 'Market' ],
active: 'Limit',
}),
<button
v-for="(n, i) in buttons"
:class="`btn btn${i + 1} ${n === active ? 'active-btn' : ''}`"
@click="active = n"
>{{ n }}</button>
<YandexClusterer
@vue:mounted="onClustererMounted"
...
methods: {
onClustererMounted(e) {
e.component.exposed.events.add('click', обработчикКлика);
},
...
@click.stop
).data: () => ({
openedPopup: null,
}),
methods: {
togglePopup(popup) {
this.openedPopup = this.openedPopup === popup ? null : popup;
},
},
@click="togglePopup('search')"
v-show="openedPopup === 'search'"
const { filledColor: F, emptyColor: E, ...props } = defineProps({
value: Number,
maxValue: Number,
segments: {
type: Number,
default: 5,
},
filledColor: {
type: String,
default: 'red',
},
emptyColor: {
type: String,
default: 'black',
},
});
const background = val =>
val >= 1 ? F :
val <= 0 ? E :
`linear-gradient(to right, ${F}, ${F}, ${val * 100}%, ${E} ${val * 100}%)`;
<div class="rating">
<div
v-for="i in segments"
:style="{ background: background(value / maxValue * segments - i + 1) }"
class="rating-segment"
></div>
</div>
const sortedData = useMemo(() => {
return data
.pages
.flatMap(n => n.data)
.sort((a, b) => b.liked.length - a.liked.length);
}, [ data ]);
<div className="App">
{sortedData.map((item) => (
<div>
...
str.match(/\d+/g).join('.')
$arr2 = array_combine(array_column($arr, 'sku'), $arr);
$result = array_map(fn($n) => $arr2[$n], $torgPred);
$result = array_filter($arr, fn($n) => in_array($n['sku'], $torgPred));