index.vue 896 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <div ref="chartElement" class="app-echarts" :style="{ width: width, height: height }"></div>
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, PropType, watch } from 'vue'
  6. import { ECOption } from './core'
  7. import { useEcharts } from './setup'
  8. export default defineComponent({
  9. props: {
  10. // 图表宽度
  11. width: {
  12. type: String,
  13. default: '100%',
  14. },
  15. // 图表高度
  16. height: {
  17. type: String,
  18. default: '100%',
  19. },
  20. // 图表配置项
  21. option: {
  22. type: Object as PropType<ECOption>,
  23. default: () => ({}),
  24. },
  25. dataIndex: {
  26. type: Number,
  27. default: 0,
  28. },
  29. },
  30. setup(props) {
  31. const { chartElement, setOptions } = useEcharts();
  32. watch(() => props.option, (val) => setOptions(val));
  33. return {
  34. chartElement,
  35. }
  36. }
  37. })
  38. </script>
  39. <style lang="less">
  40. @import './index.less';
  41. </style>