const formTemplate = `<здесь html-код формы>`;
$(document).on('change', 'селектор чекбокса', function() {
const $el = $(this).closest('селектор формы');
if (this.checked) {
$el.after(formTemplate);
} else {
$el.nextAll('селектор формы').remove();
}
});
@click="testClickGo().restart"
targets: '.testVal',
data: () => ({
anime: null,
}),
mounted() {
this.anime = this.$anime({
targets: this.$refs.animeEl,
translateX: 200,
delay: 800,
});
},
<h1 ref="animeEl">hello, world!!</h1>
<button @click="anime.restart()">click me</button>
v-model
.const group = (arr, keyProp, childrenProp) =>
Object.values(arr.reduce((acc, { [childrenProp]: children, ...n }) => {
const item = acc[n[keyProp]] = acc[n[keyProp]] || n;
if (children) {
children = (item.childItems || []).concat(children);
item[childrenProp] = group(children, keyProp, childrenProp);
}
return acc;
}, {}));
const grouped = group(products, 'name', 'childItems');
switch (true) {
case one.includes(inp):
...
break;
case two.includes(inp):
...
break;
}
const arr = [
{
values: [ ... ],
action: () => { ... },
},
{
values: [ ... ],
action: () => { ... },
},
];
arr.find(n => n.values.includes(inp))?.action();
preg_match_all('~(?<=<p>).+?(?=</p>)~', $str, $match);
$data = array_map(function($n) {
return explode('-', $n, 2);
}, $match[0]);
str.split('"').filter((n, i) => i & 1)
// или
str.match(/".*?"/g)?.map(n => n.slice(1, -1)) ?? []
// или
Array.from(str.matchAll(/"([^"]*)"/g), n => n[1])
// или
Array.prototype.reduce.call(str, (acc, n) => {
if (n !== '"') {
acc[1]?.push(n);
} else if (acc[1]) {
acc[0].push(acc[1].join(''));
acc[1] = null;
} else {
acc[1] = [];
}
return acc;
}, [ [], null ])[0]
Если происходит перемещение элементов, то счетчик увеличивается на 3, потому что происходит 3 операции с элементами.
[ arr[j - 1], arr[j] ] = [ arr[j], arr[j - 1] ];
swap(arr, j - 1, j); // функция меняет местами элементы, но как именно - вам неизвестно
делаю все как показано в примере в оф. репозитории
API: Container
Component that contains the draggable elements or components. Each of its children should be wrapped by Draggable component
<Container @drop="$emit('drop', row.id)" :get-child-payload="getChildPayload"> <div class="row">
const result = arr1.map((n, i) => {
const index = Math.min(i * 2, ((arr2.length - 2) / 2 | 0) * 2);
return `name: ${n} val1: ${arr2[index]} val2: ${arr2[index + 1]}`;
});
result.forEach(alert);
arr.reduce((acc, n, i) => (
(i && (acc[acc.length - 1].length + !(acc.length & 1) !== 3)) || acc.push([]),
acc[acc.length - 1].push(n),
acc
), [])
с перезагрузкой страницы
el.remove()
) или делайте неактивными (el.disabled = true
). Например:<form @submit="onSubmit">
<div v-for="(v, k) in formData">
<div>{{ k }}:</div>
<div><input v-model="formData[k]" :name="k" :ref="k"></div>
</div>
<button>submit</button>
</form>
data: () => ({
formData: {
forename: '',
surname: '',
email: '',
},
}),
methods: {
onSubmit() {
Object.entries(this.formData).forEach(([ k, v ]) => !v && (this.$refs[k][0].disabled = true));
},
},
{ старый_текст: новый_текст }
:const months = Object.fromEntries(Array.from({ length: 12 }, (n, i) => {
const d = new Date(0, i);
return [
d.toLocaleString('en-US', { month: 'long' }),
d.toLocaleString('ru-RU', { month: 'long' }).replace(/./, m => m.toUpperCase()),
];
}));
$('.text').text((i, text) => months[text.trim()]);
// или
document.querySelectorAll('.text').forEach(n => {
n.innerText = months[n.innerText] || n.innerText;
});
// или
for (const n of document.getElementsByClassName('text')) {
n.textContent = months[n.textContent.trim()] || n.textContent;
}