fix: move events collecting from init to setup

This commit is contained in:
Yue JIN
2024-04-23 14:17:23 +08:00
committed by GU Yiling
parent 898195c770
commit 09808a47d2

View File

@ -101,22 +101,6 @@ export default defineComponent({
// @ts-expect-error listeners for Vue 2 compatibility
const listeners = getCurrentInstance().proxy.$listeners;
function init(option?: Option) {
if (!inner.value) {
return;
}
const instance = (chart.value = initChart(
inner.value,
realTheme.value,
realInitOptions.value
));
if (props.group) {
instance.group = props.group;
}
const realListeners: Record<string, any> = {};
if (!listeners) {
@ -136,9 +120,9 @@ export default defineComponent({
// Collect native DOM events
if (event.indexOf("native:") === 0) {
// native:click -> onClick
const nativeKey = `on${event
.charAt(7)
.toUpperCase()}${event.slice(8)}`;
const nativeKey = `on${event.charAt(7).toUpperCase()}${event.slice(
8
)}`;
nativeListeners[nativeKey] = attrs[key];
return;
@ -163,14 +147,28 @@ export default defineComponent({
// &~!native:click -> &~!click
Object.keys(listeners).forEach(key => {
if (NATIVE_EVENT_RE.test(key)) {
nativeListeners[key.replace(NATIVE_EVENT_RE, "$1")] =
listeners[key];
nativeListeners[key.replace(NATIVE_EVENT_RE, "$1")] = listeners[key];
} else {
realListeners[key] = listeners[key];
}
});
}
function init(option?: Option) {
if (!inner.value) {
return;
}
const instance = (chart.value = initChart(
inner.value,
realTheme.value,
realInitOptions.value
));
if (props.group) {
instance.group = props.group;
}
Object.keys(realListeners).forEach(key => {
let handler = realListeners[key];