mirror of
https://github.com/ecomfe/vue-echarts.git
synced 2025-08-16 04:31:22 +08:00
feat: also supports native:
in Vue 2
This commit is contained in:
16
README.md
16
README.md
@ -466,28 +466,12 @@ See supported events [here →](https://echarts.apache.org/en/api.html#events)
|
|||||||
|
|
||||||
#### Native DOM Events
|
#### Native DOM Events
|
||||||
|
|
||||||
<details open>
|
|
||||||
<summary>Vue 3</summary>
|
|
||||||
|
|
||||||
```vue
|
```vue
|
||||||
<template>
|
<template>
|
||||||
<v-chart @native:click="handleClick" />
|
<v-chart @native:click="handleClick" />
|
||||||
</template>
|
</template>
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
<details open>
|
|
||||||
<summary>Vue 2</summary>
|
|
||||||
|
|
||||||
```vue
|
|
||||||
<template>
|
|
||||||
<v-chart @click.native="handleClick" />
|
|
||||||
</template>
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## CSP: `style-src` or `style-src-elem`
|
## CSP: `style-src` or `style-src-elem`
|
||||||
|
|
||||||
If you are applying a CSP to prevent inline `<style>` injection, you need to use files from `dist/csp` directory and include `dist/csp/style.css` into your app manually.
|
If you are applying a CSP to prevent inline `<style>` injection, you need to use files from `dist/csp` directory and include `dist/csp/style.css` into your app manually.
|
||||||
|
@ -126,7 +126,7 @@ export default defineComponent({
|
|||||||
// onZr:click -> z + r:click
|
// onZr:click -> z + r:click
|
||||||
let event = key.charAt(2).toLowerCase() + key.slice(3);
|
let event = key.charAt(2).toLowerCase() + key.slice(3);
|
||||||
|
|
||||||
// Collect native events
|
// Collect native DOM events
|
||||||
if (event.startsWith("native:")) {
|
if (event.startsWith("native:")) {
|
||||||
// native:click -> onClick
|
// native:click -> onClick
|
||||||
const nativeKey =
|
const nativeKey =
|
||||||
@ -144,6 +144,18 @@ export default defineComponent({
|
|||||||
|
|
||||||
realListeners[event] = attrs[key];
|
realListeners[event] = attrs[key];
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
// Vue 2 native DOM events
|
||||||
|
Object.keys(realListeners).forEach(key => {
|
||||||
|
const index = key.indexOf("native:");
|
||||||
|
if (index === 0 || index === 1 || index === 2) {
|
||||||
|
// native:click -> click
|
||||||
|
// ~native:click -> ~click
|
||||||
|
// ~!native:click -> ~!click (eg: .capture.once)
|
||||||
|
nativeEventAttrs[key.slice(0, index) + key.slice(index + 7)] =
|
||||||
|
realListeners[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.keys(realListeners).forEach(key => {
|
Object.keys(realListeners).forEach(key => {
|
||||||
@ -316,7 +328,7 @@ export default defineComponent({
|
|||||||
// See https://v3-migration.vuejs.org/breaking-changes/render-function-api.html#vnode-props-format
|
// See https://v3-migration.vuejs.org/breaking-changes/render-function-api.html#vnode-props-format
|
||||||
const attrs = (
|
const attrs = (
|
||||||
Vue2
|
Vue2
|
||||||
? { attrs: this.nonEventAttrs }
|
? { attrs: this.nonEventAttrs, on: this.nativeEventAttrs }
|
||||||
: { ...this.nonEventAttrs, ...this.nativeEventAttrs }
|
: { ...this.nonEventAttrs, ...this.nativeEventAttrs }
|
||||||
) as any;
|
) as any;
|
||||||
attrs.ref = "root";
|
attrs.ref = "root";
|
||||||
|
Reference in New Issue
Block a user