index.vue 755 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <template>
  2. <div :id="chartId" style="width: 100%;height: 160px" />
  3. </template>
  4. <script>
  5. import echarts from 'echarts'
  6. export default {
  7. name: 'Hello',
  8. props: {
  9. chartId: {
  10. type: String,
  11. default: 'myChart'
  12. },
  13. option: {
  14. type: Object,
  15. default() {
  16. return {}
  17. }
  18. }
  19. },
  20. data() {
  21. return {
  22. msg: 'Welcome to Your Vue.js App'
  23. }
  24. },
  25. watch: {
  26. option(newValue, oldValue) {
  27. this.drawLine()
  28. }
  29. },
  30. mounted() {
  31. this.drawLine()
  32. },
  33. methods: {
  34. drawLine() {
  35. // 基于准备好的dom,初始化echarts实例
  36. const myChart = echarts.init(document.getElementById(this.chartId))
  37. // 绘制图表
  38. myChart.setOption(this.option)
  39. }
  40. }
  41. }
  42. </script>