AP
Size: a a a
AP
MS
AP
MS
AP
AP
function custom_event(type, detail, bubbles = false) {
const e = document.createEvent('CustomEvent');
e.initCustomEvent(type, bubbles, false, detail);
return e;
}AP
<button on:click={(e) => e.target.dispatchEvent(new CustomEvent('custom-event', { detail: 'hello world' }))}AP
AP
function createCustomEventDispatcher() {
const dispatch = createEventDispatcher();
return (name, detail, target, bubbles) => {
dispatch(name, detail);
target?.dispatchEvent(new CustomEvent(name, { detail, bubbles }));
};
}
и делать потом (e) => dispatch('custom', 'some-data', e.target, true);MS
AP
MS
AP
AP
<Component on:custom={doSomething}/> здесь нет дом элементаMS
AP
MS
AP
AP
MS