@neatui/vue 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neatui/vue",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "basic component ui",
5
5
  "main": "./src/index.ts",
6
6
  "license": "MIT",
@@ -0,0 +1,59 @@
1
+ <template>
2
+ <div ref="dom"></div>
3
+ </template>
4
+ <script setup lang="ts">
5
+ import { ref, watch, onMounted, onBeforeUnmount } from 'vue';
6
+ import ResizeObserver from 'resize-observer-polyfill';
7
+ import * as echarts from 'echarts';
8
+
9
+ // 类型
10
+ interface Props {
11
+ option?: object;
12
+ }
13
+
14
+ // 入参
15
+ const props: any = withDefaults(defineProps<Props>(), {
16
+ option: () => ({})
17
+ });
18
+
19
+ const dom: any = ref(null);
20
+ let obs: any = null;
21
+ let ex: any = null;
22
+ let timer: any = null;
23
+
24
+ // 重绘
25
+ const redraw = () => {
26
+ if (ex) {
27
+ clearTimeout(timer);
28
+ timer = setTimeout(() => {
29
+ ex?.resize();
30
+ }, 3);
31
+ }
32
+ };
33
+
34
+ watch(
35
+ () => props.option,
36
+ () => {
37
+ if (ex) {
38
+ ex?.setOption(props.option);
39
+ }
40
+ },
41
+ { deep: true }
42
+ );
43
+
44
+ onMounted(() => {
45
+ if (dom.value) {
46
+ ex = echarts.init(dom.value);
47
+ ex?.setOption(props.option);
48
+
49
+ // 监听参考元素变化
50
+ obs = new ResizeObserver(redraw);
51
+ obs?.observe(dom.value);
52
+ }
53
+ });
54
+
55
+ onBeforeUnmount(() => {
56
+ // 清除监听参考元素变化;
57
+ obs?.disconnect();
58
+ });
59
+ </script>
@@ -3,5 +3,6 @@ import Tree from './Tree.vue';
3
3
  import Calendar from './Calendar.vue';
4
4
  import PhotoEditor from './PhotoEditor.vue';
5
5
  import TreeView from './TreeView.vue';
6
+ import ChartView from './ChartView.vue';
6
7
 
7
- export { Image, Tree, Calendar, PhotoEditor, TreeView };
8
+ export { Image, Tree, Calendar, PhotoEditor, TreeView, ChartView };