.list-enter-from {
transition-group
следует добавить параметр appear
. fetch('https://jsonplaceholder.typicode.com/todos/1')
1
.const [data, setData] = useState(null);
{data.map(item => (
null
метод map
? - погуглите, разберитесь. Ну и замените null
на []
. const radios = document.querySelectorAll('[name="radios"]');
const selects = Array.from(radios, n => n.nextElementSibling);
const onChange = e => selects.forEach(n => n.disabled = n !== e.target.nextElementSibling);
radios.forEach(n => n.addEventListener('change', onChange));
data.each_value{|n|
puts("#{n[:name]}: вес #{n[:weight]} г., количество #{n[:qty]} шт.")
}
const arithmeticProgression = ({ length, a1 = 0, d = 1 }) =>
Array.from(
{ length },
(n, i) => a1 + i * d
);
const arr = arithmeticProgression({
length: 10,
a1: 6,
d: 3,
});
function* arithmeticProgression(a1, d, length) {
for (let i = 0; i < length; i++) {
yield a1 + i * d;
}
}
for (const n of arithmeticProgression(100, 10, 5)) {
console.log(n);
}
console.log(Array.from(arithmeticProgression(10, -7, 10)));
def fucking_filter(arr, max_count, key=lambda n: n):
filtered = []
count = {}
for n in arr:
k = key(n)
count[k] = count.get(k, 0) + 1
if count[k] <= max_count:
filtered.append(n)
return filtered
for n in fucking_filter(genres, N):
print(n)
хочу сделать задержку ввода
methods: {
onInput: debounce(function(val) {
this.debouncedInput = val;
}, 500),
...
<v-text-field
@input="onInput"
...
computed: {
count() {
return this.orders.map(n => n.count);
},
},
watch: {
count: debounce(function(newVal, oldVal) {
this.debouncedInput = newVal.find((n, i) => n !== oldVal[i]);
}, 500),
},
data: () => ({
links: [ 'tasks', 'kanban', 'activity', 'calendar', 'files' ],
}),
ul
li(v-for="n in links")
router-link(:to="{ name: n }") {{ n }}
.marker
div(v-for="n in links" :class="[ `select${n}`, $route.name === n ? 'active' : '' ]")
span
const certificate = ref({});
shortingTechItems(certificate.pto)
прилетает undefined
В чем проблема
как исправить?
- const shortingTechItems = (item) => {
- const arr = [];
- item.map((i) => {
- arr.push(Number(i.replace(/\D+/g, "")));
- });
- return arr;
- };
+ const shortingTechItems = items => items.map(n => +n.replace(/\D/g, ''));
props: [ 'value' ],
provide() {
return {
radioGroup: this,
};
},
props: [ 'value' ],
inject: [ 'radioGroup' ],
<input
type="radio"
:value="value"
:checked="radioGroup.value === value"
@change="radioGroup.$emit('input', value)"
>
props: [ 'modelValue' ],
emits: [ 'update:modelValue' ],
setup(props, { emit }) {
provide('radioGroupValue', computed({
get: () => props.modelValue,
set: v => emit('update:modelValue', v),
}));
},
props: [ 'value' ],
setup() {
return {
radioGroupValue: inject('radioGroupValue'),
};
},
<input
type="radio"
:value="value"
v-model="radioGroupValue"
>
const voidTags = [ 'input', 'img', 'br', 'hr', ещё какой-то тэг, и ещё, ... ];
function createHTML(data) {
const attrs = Object
.entries(data.attrs ?? {})
.map(n => `${n[0]}="${n[1]}"`)
.join(' ');
const startTag = `<${data.tagName}${attrs && (' ' + attrs)}>`;
if (voidTags.includes(data.tagName)) {
return startTag;
}
const children = (data.subTags ?? [])
.map(createHTML)
.join('');
return `${startTag}${data.text ?? ''}${children}</${data.tagName}>`;
}
Vue cannot detect the following changes to an array <...> When you directly set an item with the index
filterRS.filter_range_value = [ selected_start, selected_end ];
v-model
один массив и для select'ов и для range'а, без необходимости заниматься ручной синхронизацией. А там, где значения надо представить в человекопонятном виде, это можно делать через вычисляемое свойство - например, так. 0
) и переполнения предыдущего разряда. Цифра разряда нового числа - младший разряд суммы (т.е., остаток от деления на 10
).function sum(a, b) {
const result = [];
for (
let i = ~-a.length, j = ~-b.length, overflow = 0;
i >= 0 || j >= 0 || overflow;
i--, j--
) {
const digit = (a[i] | 0) + (b[j] | 0) + overflow;
overflow = +(digit > 9);
result.push(digit % 10);
}
return result.reverse();
}
const search = ` ${str}.`;
const item = arr.find(n => n.includes(search));
const test = RegExp.prototype.test.bind(RegExp(`\\b${str}\\b`));
const items = arr.filter(test);
контейнерСсылок.addEventListener('click', e => {
const index = e.target.dataset.index;
if (index) {
массивМеток[index].balloon.open();
}
});
массивМеток.forEach(n => {
n.events.add('balloonopen', onBalloonOpen);
n.events.add('balloonclose', onBalloonClose);
});
function onBalloonOpen(e) {
const index = e.get('target').properties.get('index');
const link = контейнерСсылок.children[index]; /* или, если структура списка ссылок более сложная,
* как в примере из документации, можно искать нужную
* через .querySelector(`[data-index="${index}"]`)
*/
link.scrollIntoView({
behavior: 'smooth',
});
link.classList.add('active');
}
function onBalloonClose(e) {
const index = e.get('target').properties.get('index');
контейнерСсылок.children[index].classList.remove('active');
}
.highlight {
color: white;
background: red;
}
methods: {
highlightNames: str => str.replace(/(?<=^|\s)@\S+/g, '<span class="highlight">$&</span>'),
},
<div v-html="highlightNames(item.text)"></div>
arr.map((n, i, a) => a.slice(0, i + 1).join(''))
// или
arr.reduce((acc, n) => (acc.push((acc.at(-1) ?? '') + n), acc), [])
(function xxx(arr, str = '') {
if (str.length === arr.length) {
return [];
}
const newStr = str.concat(arr[str.length]);
return [ newStr, ...xxx(arr, newStr) ];
})(arr)
отфильтровать массив по введенному значению в строке поиска в watch-ере
computed: {
filteredProjects() {
const search = this.searchString.toLowerCase();
return this.journal.flatMap(n => {
return n.savedProjects.filter(m => m.name.toLowerCase().includes(search));
});
},
...