feat: 优化监听vCharts配置的写法

This commit is contained in:
奔跑的面条
2024-12-24 17:35:53 +08:00
parent a698191873
commit 5b37edc558
2 changed files with 18 additions and 7 deletions
+16 -3
View File
@@ -8,7 +8,7 @@
</template>
<script setup lang="ts">
import { ref, PropType, watch, onBeforeUnmount, nextTick, toRaw } from 'vue'
import { ref, PropType, watch, onBeforeUnmount, nextTick, toRaw, toRefs } from 'vue'
import { VChart, type IVChart, type IInitOption, type ISpec } from '@visactor/vchart'
import { transformHandler } from './transformProps'
import { IOption } from '@/packages/components/VChart/index.d'
@@ -156,11 +156,13 @@ const props = defineProps({
const vChartRef = ref()
let chart: IVChart
// 解构 props.option,排除 dataset
const { dataset, ...restOfOption } = toRefs(props.option)
// 排除 data 监听
watch(
() => ({
...props.option,
dataset: undefined
...restOfOption
}),
() => {
nextTick(() => {
@@ -172,6 +174,17 @@ watch(
immediate: true
}
)
watch(
() => dataset.value,
() => {
nextTick(() => {
createOrUpdateChart(props.option)
})
},
{
deep: false
}
)
// 更新
const createOrUpdateChart = (