Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vue 数据不更新 #1707

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/vue/examples/vue3/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default {
this.year = '2022';
this.chartData = data2;
}, 1000);
setTimeout(() => {
this.year = '2021';
this.chartData = data1;
}, 3000);
},
render() {
const { year, chartData } = this;
Expand Down
18 changes: 9 additions & 9 deletions packages/vue/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ export default {
getProps() {
const { $props, $slots } = this;
const props = toRaw($props);
props.children = toRawChildren($slots);
return props;
const canvasEl = this.$el;
const context = canvasEl.getContext('2d');
return {
...props,
// context 内部创建,不能被覆盖
context,
children: toRawChildren($slots),
};
},
},
mounted() {
const canvasEl = this.$el;
const context = canvasEl.getContext('2d');
const props = this.getProps();
const canvas = new Canvas({
...props,
// context 内部创建,不能被覆盖
context,
});
const canvas = new Canvas(props);
canvas.render();
this.canvas = canvas;
},
Expand Down