mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2025-08-15 03:33:19 +08:00
fix(#519): replace mergeProps with simplified logic
This commit is contained in:
@ -12,7 +12,6 @@ import {
|
|||||||
onMounted,
|
onMounted,
|
||||||
onUnmounted,
|
onUnmounted,
|
||||||
h,
|
h,
|
||||||
mergeProps,
|
|
||||||
PropType,
|
PropType,
|
||||||
watchEffect,
|
watchEffect,
|
||||||
Vue2
|
Vue2
|
||||||
@ -36,7 +35,7 @@ import {
|
|||||||
loadingProps
|
loadingProps
|
||||||
} from "./composables";
|
} from "./composables";
|
||||||
import "./style.css";
|
import "./style.css";
|
||||||
import { filterObjectValue } from "./utils";
|
import { omitOn } from "./utils";
|
||||||
|
|
||||||
const TAG_NAME = "x-vue-echarts";
|
const TAG_NAME = "x-vue-echarts";
|
||||||
|
|
||||||
@ -95,9 +94,7 @@ export default defineComponent({
|
|||||||
const initOptions = toRef(props, "initOptions");
|
const initOptions = toRef(props, "initOptions");
|
||||||
const loadingOptions = toRef(props, "loadingOptions");
|
const loadingOptions = toRef(props, "loadingOptions");
|
||||||
|
|
||||||
const nonEventAttrs = computed(() =>
|
const nonEventAttrs = computed(() => omitOn(attrs));
|
||||||
filterObjectValue(attrs, value => typeof value !== "function")
|
|
||||||
);
|
|
||||||
|
|
||||||
function init(option?: Option) {
|
function init(option?: Option) {
|
||||||
if (chart.value || !root.value) {
|
if (chart.value || !root.value) {
|
||||||
@ -244,9 +241,9 @@ export default defineComponent({
|
|||||||
return exposed;
|
return exposed;
|
||||||
},
|
},
|
||||||
render() {
|
render() {
|
||||||
return h(
|
const attrs = { ...this.nonEventAttrs };
|
||||||
TAG_NAME,
|
attrs.ref = "root";
|
||||||
mergeProps({ class: "echarts", ref: "root" }, this.nonEventAttrs)
|
attrs.class = attrs.class ? ["echarts"].concat(attrs.class) : "echarts";
|
||||||
);
|
return h(TAG_NAME, attrs);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
24
src/utils.ts
24
src/utils.ts
@ -1,16 +1,20 @@
|
|||||||
type Attrs = {
|
type Attrs = {
|
||||||
[key: string]: unknown;
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function filterObjectValue(
|
// Copied from
|
||||||
source: Attrs,
|
// https://github.com/vuejs/vue-next/blob/5a7a1b8293822219283d6e267496bec02234b0bc/packages/shared/src/index.ts#L40-L41
|
||||||
predicate: (key: unknown) => boolean
|
const onRE = /^on[^a-z]/;
|
||||||
) {
|
export const isOn = (key: string) => onRE.test(key);
|
||||||
const target: Attrs = {};
|
|
||||||
for (const key in source) {
|
export function omitOn(attrs: Attrs) {
|
||||||
if (predicate(source[key])) {
|
const result: Attrs = {};
|
||||||
target[key] = source[key];
|
for (const key in attrs) {
|
||||||
|
if (!isOn(key)) {
|
||||||
|
result[key] = attrs[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return target;
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user