gpt4 book ai didi

vue自己封装一个echart公共组件

转载 作者:知者 更新时间:2024-03-13 03:51:33 27 4
gpt4 key购买 nike

<template>
	<div class="echarts"></div>
</template>

<script>
	import * as echarts from 'echarts'
	import {
		markRaw
	} from 'vue'
	export default {
		props: {
			isUpdate: String,
			option: {
				type: Object,
				default: function () {
					return {
						type: 'default'
					}
				}
			}
		},
		watch: {
			// 防止配置改变后不更新配置,重新加载配置即可
			option: {
				deep: true,
				handler() {
					if (this.chart) {
						this.chart.setOption(this.option)
					}
				}
			},
			// 自适应大小
			isUpdate() {
				if (this.chart) {
					this.chart.resize()
				}
			}
		},
		data() {
			return {
				chart: null
			}
		},
		mounted() {
			this.initChart()
		},
		methods: {
			initChart() {
				this.chart = markRaw(echarts.init(this.$el, 'dark')) //获取自身dom元素
				// this.chart = echarts.init(this.$el, 'dark')
				if (this.option.type != 'default') {
					this.chart.setOption(this.option)
				}
			}
		}
	}
</script>

<style scoped="scoped">
	.echarts {
		width: 100%;
		height: 100%;
	}
</style>

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com