欢迎访问 生活随笔!

凯发ag旗舰厅登录网址下载

当前位置: 凯发ag旗舰厅登录网址下载 > 前端技术 > vue >内容正文

vue

vue——整合echart -凯发ag旗舰厅登录网址下载

发布时间:2024/10/5 vue 30 豆豆
凯发ag旗舰厅登录网址下载 收集整理的这篇文章主要介绍了 vue——整合echart 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

凯发ag旗舰厅登录网址下载的解决方案

<template><div :style="{ height: height, width: width }" /> </template><script lang="ts"> import { definecomponent } from 'vue'export default definecomponent({name: 'echarts', }) </script><script lang="ts" setup> import * as echarts from 'echarts' import 'echarts/theme/macarons' import { debounce } from '@/utils/debounce' import {nexttick,onmounted,onunmounted,shallowref,getcurrentinstance,watcheffect, } from 'vue' import { echartstype } from 'echarts'const instance = getcurrentinstance()const props = defineprops({options: {type: object,required: true,},width: {type: string,default: '100%',},height: {type: string,default: '100%',}, })const chart = shallowref<echartstype>()const initchart = () => {if (instance) {chart.value = echarts.init(instance.proxy?.$el, 'macarons')chart.value?.setoption(props.options)} }const resizehandler = debounce(() => {if (chart.value) {chart.value.resize()} }, 100)onmounted(() => {nexttick(() => {initchart()window.addeventlistener('resize', resizehandler)}) })onunmounted(() => {if (!chart.value) {return}window.removeeventlistener('resize', resizehandler)chart.value.dispose()chart.value = undefined })watcheffect(() => {if (chart.value) {chart.value.setoption(props.options)} }) </script><style lang="scss" scoped></style>

demo

<e-charts :options="options" height="300px" />

options 即 echarts 的options

参考文章

  • https://echarts.apache.org/
  • vue3封装简易的vue-echarts
  • vue-cli3整合echarts

总结

以上是凯发ag旗舰厅登录网址下载为你收集整理的vue——整合echart的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。

  • 上一篇:
  • 下一篇:
网站地图