Skip to content

Commit

Permalink
fix: vue 数据不更新 (#1707)
Browse files Browse the repository at this point in the history
Co-authored-by: xuying.xu <xuying.xu@alibaba-inc.com>
  • Loading branch information
tangying1027 and xuying.xu committed Jan 16, 2023
1 parent 8660a81 commit 6f15e4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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

0 comments on commit 6f15e4a

Please sign in to comment.