Jelajahi Sumber

perf(components): 修复“折线图”组件数据叠加问题

wangshun 1 bulan lalu
induk
melakukan
2a0eedd834
1 mengubah file dengan 5 tambahan dan 5 penghapusan
  1. 5 5
      src/components/LineChart.vue

+ 5 - 5
src/components/LineChart.vue

@@ -31,7 +31,7 @@ use([
   MarkLineComponent,
 ]);
 
-const list: number[] = [];
+const list = ref<number[]>([]);
 
 interface Props {
   data: MonitoringPointData;
@@ -44,13 +44,12 @@ const emit = defineEmits(['editorClick', 'historicalDataClick']);
 const props = defineProps<Props>();
 
 const getCurvedData = () => {
+  list.value = [];
   if (props.data.tempData) {
     props.data.tempData.forEach((item) => {
-      list.push(item.value);
+      list.value.push(item.value);
     });
   }
-
-  return list;
 };
 
 const getColor = (value: number) => {
@@ -80,6 +79,7 @@ const getColor = (value: number) => {
 };
 
 const option = computed(() => {
+  getCurvedData();
   if (!props.data) return {};
   return {
     backgroundColor: getColor(2),
@@ -99,7 +99,7 @@ const option = computed(() => {
     series: [
       {
         type: 'line',
-        data: getCurvedData(),
+        data: list.value,
         symbol: 'none', // 不显示数据点
         color: getColor(1),
         lineStyle: {