在vue中實(shí)現(xiàn)清除echarts上次保留的數(shù)據(jù)(親測有效)
因?yàn)槲沂菍charts封裝好后,父組件只要傳遞值就可以進(jìn)行渲染。
但是點(diǎn)擊多次數(shù)據(jù)請求的時(shí)候echarts會(huì)多次渲染。如果試過
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. Yii2.0引入CSS,JS文件方法2. 解決啟動(dòng)django,瀏覽器顯示“服務(wù)器拒絕訪問”的問題3. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析4. vue使用webSocket更新實(shí)時(shí)天氣的方法5. Nginx+php配置文件及原理解析6. 關(guān)于HTML5的img標(biāo)簽7. python virtualenv和flask安裝沒有名為flask的模塊8. CSS3實(shí)現(xiàn)動(dòng)態(tài)翻牌效果 仿百度貼吧3D翻牌一次動(dòng)畫特效9. java中throws實(shí)例用法詳解10. 討論CSS中的各類居中方式
