在vue中实现echarts随窗口变化自动调整大小,并且使用lodash实现防抖

231 阅读1分钟
//1.安装
npm i --save lodash
//2.main.js引入,直接在组件中引入
// import _ from 'lodash'
 //Vue.prototype._ = _
//3.组件中
 import _ from 'lodash'
mounted() {
	this.chart = this.$echarts.init(this.$refs.chart)
	this.chart.setOption(this.createOption(), true)
	window.addEventListener('resize', this.resizeFn)
		},
beforeDestroy() {
	window.removeEventListener('resize', this.resizeFn)
},
methods: {
	resizeFn:_.debounce(function(){
		this.resizeChart()
	},150),
	resizeChart(){
		console.log('=====================')
                //如果字体大小需要计算				 
                //this.chart.setOption(this.createOption(), true)
        this.chart.resize()
			},	
	createOption() {。。。。。}
}