在vue中實(shí)現(xiàn)清除echarts上次保留的數(shù)據(jù)(親測有效)
因?yàn)槲沂菍charts封裝好后,父組件只要傳遞值就可以進(jìn)行渲染。
但是點(diǎn)擊多次數(shù)據(jù)請求的時(shí)候echarts會多次渲染。如果試過
clear() 與setOption(this.options, true)沒用之后。可以試一下下面的方法。
首先是在父組件中對數(shù)據(jù)進(jìn)行請求,在賦值之前,先清空。
data里定義的三組echarts數(shù)據(jù)
在axios發(fā)送請求后
先清空再賦值。
補(bǔ)充知識:vue.js使用vue-echarts給柱形圖綁定點(diǎn)擊事件
我就廢話不多說了,大家還是直接看代碼吧~
<template> <div class='echarts'> <IEcharts :option='bar' :loading='loading' @ready='onReady' @click='onClick'></IEcharts> <button @click='doRandom'>Random</button> </div></template> <script type='text/babel'> import IEcharts from ’vue-echarts-v3/src/full.js’; export default { name: ’view’, components: { IEcharts }, props: { }, data: () => ({ loading: true, bar: { title: { text: ’ECharts Hello World’ }, tooltip: {}, xAxis: { data: [’Shirt’, ’Sweater’, ’Chiffon Shirt’, ’Pants’, ’High Heels’, ’Socks’] }, yAxis: {}, series: [{ name: ’Sales’, type: ’bar’, data: [5, 20, 36, 10, 10, 20] }] } }), methods: { doRandom() { const that = this; let data = []; for (let i = 0, min = 5, max = 99; i < 6; i++) { data.push(Math.floor(Math.random() * (max + 1 - min) + min)); } that.loading = !that.loading; that.bar.series[0].data = data; }, onReady(instance) { console.log(instance); }, onClick(event, instance, echarts) { console.log(arguments); } } };</script> <style scoped> .echarts { width: 400px; height: 400px; }</style>
以上這篇在vue中實(shí)現(xiàn)清除echarts上次保留的數(shù)據(jù)(親測有效)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. web下載文件和跳轉(zhuǎn)的方法2. ASP中常用的22個(gè)FSO文件操作函數(shù)整理3. PHP函數(shù)原理理解詳談4. React+umi+typeScript創(chuàng)建項(xiàng)目的過程5. SharePoint Server 2019新特性介紹6. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析7. Vue+elementUI下拉框自定義顏色選擇器方式8. ASP的Global.asa文件技巧用法9. ASP中if語句、select 、while循環(huán)的使用方法10. JSP頁面實(shí)現(xiàn)驗(yàn)證碼校驗(yàn)功能
