Пробовал через emit передать, но получилось перехватить событие только в App.vue, но не в Modal.vue
const container = document.querySelector('.buttons');
const buttonSelector = '.button';
const onButtonClick = button => console.log(button.id);
container.addEventListener('click', e => {
const button = e.target.closest(buttonSelector);
if (button) {
onButtonClick(button);
}
});
container.querySelectorAll(buttonSelector).forEach(function(n) {
n.addEventListener('click', this);
}, e => onButtonClick(e.currentTarget));
Например если число 200000
useEffect(() => {
axios.get('/api/products/random-lucky-box').then(r => setProduct(r.data));
}, []);
useEffect(() => {
if (product.catId) {
axios.get(`/api/categories/${product.catId}`).then(r => setCategory(r.data));
}
}, [ product ]);
const bullshitDateFormat = str =>
new Date(+str.replace(/\D/g, ''))
.toLocaleString('ru-RU')
.slice(0, -3)
.replace(',', '');
.slice(0, -3)
выглядит сильно так себе (с другой стороны - коротко), вместо него можно в явном виде (второй параметр) указать при вызове toLocaleString, какие элементы даты надо получить:{
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
}
HTML5 specifies that a <script>
tag inserted with innerHTML should not execute.
script
вручную. Точнее - заменим тот, что есть, на новый с таким же src.div(v-html="сontent" ref="content")
watch: {
content() {
this.$nextTick(() => {
const oldScript = this.$refs.content.querySelector('script');
const newScript = document.createElement('script');
newScript.src = oldScript.src;
oldScript.parentNode.replaceChild(newScript, oldScript);
});
},
},
Object.values(arr.reduce((acc, n) => {
const name = n.name.split(' ').pop();
acc[name] = +acc[name]?.price < +n.price ? acc[name] : n;
return acc;
}, {}))
data: () => ({
activeItem: null,
items: [
{
id: 69,
name: 'hello, world!!',
colors: [ 'white', 'blue', 'red' ],
color: null,
},
{
id: 187,
name: 'fuck the world',
colors: [ 'red', 'green', 'blue' ],
color: null,
},
{
id: 666,
name: 'fuck everything',
colors: [ '#fb1', '#e2c', '#3a9', '#cb9' ],
color: null,
},
],
}),
<v-btn-toggle class="mb-10" v-model="activeItem">
<v-btn color="#546E7A" v-for="n in items" :key="n.id" :value="n">
{{ n.name }}
<v-badge v-if="n.color" :color="n.color" bordered inline tile></v-badge>
</v-btn>
</v-btn-toggle>
<v-spacer></v-spacer>
<v-btn-toggle v-if="activeItem" v-model="activeItem.color">
<v-btn v-for="n in activeItem.colors" :key="n" :color="n" :value="n"></v-btn>
</v-btn-toggle>
toInsert = 'test.'
newStr = str.dup.sub!(/(?<=www\.)/, toInsert) || (toInsert + str)
const result = arr.flat().map((n, i) => ({ ...n, id: -~i }));
const result = [];
for (const n of arr) {
for (const m of n) {
result.push({
...m,
id: result.length + 1,
});
}
}
context.translate(120, 120);
сделайте context.translate(120 + x_pos, 120);
, а context.fillRect(x_pos, 0, 100, 100);
замените на context.fillRect(0, 0, 100, 100);
. const coord = [ 0, 0 ];
const step = 10;
const moveFunc = e => {
const shift = ({
ArrowUp: [ 0, -1 ],
ArrowDown: [ 0, 1 ],
ArrowLeft: [ -1, 0 ],
ArrowRight: [ 1, 0 ],
})[e.code];
if (shift) {
div.style.left = `${coord[0] += shift[0] * step}px`;
div.style.top = `${coord[1] += shift[1] * step}px`;
}
};
const result = Array.from(
document.querySelectorAll('#spisok > div > p > br'),
n => n.nextSibling.textContent.trim()
);
const result = Array.prototype.map.call(
document.getElementById('spisok').getElementsByTagName('button'),
n => n.previousSibling.nodeValue.replace(/(^\s+)|(\s+$)/g, '')
);
const makeOrderList = str =>
Object.fromEntries(Array.from(
str.matchAll(/(\d+) ([^,]+)/g),
n => [ n[2].replace(/ /g, '_'), +n[1] ]
));
const makeOrderList = str => str
.split(', ')
.map(n => [ n.split(' ').slice(1).join('_'), parseInt(n) ])
.filter(n => !Number.isNaN(n[1]))
.reduce((acc, n) => (acc[n[0]] = n[1], acc), {});
const attrName = 'bst-click';
const elements = document.querySelectorAll(`[${attrName}]`);
const data = Array.from(
elements,
n => [
n.attributes[attrName].value,
n.classList.value,
]
);
const data = Array.prototype.reduce.call(
elements,
(acc, n) => (
(acc[n.getAttribute(attrName)] ??= []).push(n.className),
acc
),
{}
);
hrefs.filter(n => !/\.pdf$/.test(n))
// или
hrefs.filter(n => !n.endsWith('.pdf'))
// или
hrefs.filter(n => n.split('.').pop() !== 'pdf')
// или
hrefs.filter(n => n.lastIndexOf('.pdf') !== n.length - 4)
// или
hrefs.filter(n => n.slice(-4) !== '.pdf')
// или
hrefs.filter(n => n.replace(/.*\./, '') !== 'pdf')
// или
hrefs.filter(n => n.match(/\.[^.]+$/g) != '.pdf')
const getLast = (obj, parentName) =>
obj.next instanceof Object
? getLast(obj.next, obj.name)
: { ...obj, parentName };
function getLast(obj) {
let parentName = void 0;
for (; obj.next; parentName = obj.name, obj = obj.next) ;
return { ...obj, parentName };
}
нужно в 24 строки уложиться
return ''.join('0' if n == '1' else '1' for n in d)
return '1' if n == 1 else ((s := dracon(n - 1)) + '1' + invert(s)[::-1])
dr
, идентичны одной из веток условного оператора внутри цикла - так что удалим их, а цикл пусть сделает ещё одну итерацию, для этого в начале dr
должно оказаться что-то, отличное от '1'
.invert = lambda d: ''.join('0' if n == '1' else '1' for n in d)
dracon = lambda n: '1' if n == 1 else ((s := dracon(n - 1)) + '1' + invert(s)[::-1])
dr = '0' + dracon(int(input()))
print(dr)
import turtle as t
tt = t.Turtle()
for n in dr:
if n == '1':
tt.right(90)
tt.forward(4)
else:
tt.left(90)
tt.forward(4)
input()
:=
).