Skip to content

Commit 742bf62

Browse files
authored
fix: fix compatability with Vue >=2.7 (#967)
1 parent 4ab91cc commit 742bf62

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

.size-limit.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"path": "dist/index.js",
4-
"limit": "1.9 KB",
4+
"limit": "1.95 KB",
55
"webpack": false,
66
"running": false
77
},

src/typedCharts.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
import type { TypedChartComponent, ChartComponentRef } from './types.js'
1515
import { CommonProps } from './props.js'
1616
import { Chart } from './chart.js'
17+
import { compatProps } from './utils.js'
1718

1819
export function createTypedChart<
1920
TType extends ChartType = ChartType,
@@ -36,11 +37,18 @@ export function createTypedChart<
3637
expose({ chart: ref })
3738

3839
return () => {
39-
return h(Chart, {
40-
ref: reforwardRef as any,
41-
type,
42-
...props
43-
})
40+
return h(
41+
Chart,
42+
compatProps(
43+
{
44+
ref: reforwardRef as any
45+
},
46+
{
47+
type,
48+
...props
49+
}
50+
)
51+
)
4452
}
4553
}
4654
}) as any

src/utils.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isProxy, toRaw } from 'vue'
1+
import { isProxy, toRaw, version } from 'vue'
22
import type {
33
Chart,
44
ChartType,
@@ -8,6 +8,13 @@ import type {
88
DefaultDataPoint
99
} from 'chart.js'
1010

11+
export const compatProps =
12+
version[0] === '2'
13+
? <I extends {}, T extends {}>(internals: I, props: T) =>
14+
Object.assign(internals, { attrs: props }) as unknown as I & T
15+
: <I extends {}, T extends {}>(internals: I, props: T) =>
16+
Object.assign(internals, props)
17+
1118
export function toRawIfProxy<T>(obj: T) {
1219
return isProxy(obj) ? toRaw(obj) : obj
1320
}

website/src/migration-guides/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ If you are experiencing this problem with Jest, you should follow [this doc](htt
2121
- `chartOptions` props were renamed to `options`
2222
- unknown props will fall through to the canvas element.
2323
- `generateChart` were refactored and renamed to `createTypedChart`
24+
- Vue.js < 2.7 is no longer supported. If you want to use vue-chartjs with Vue < 2.7 you have to lock your version to 4.x.
2425

2526
## Migration from v3 to v4
2627

0 commit comments

Comments
 (0)