在vue中實現(xiàn)清除echarts上次保留的數(shù)據(jù)(親測有效)
因為我是將echarts封裝好后,父組件只要傳遞值就可以進行渲染。
但是點擊多次數(shù)據(jù)請求的時候echarts會多次渲染。如果試過
clear() 與setOption(this.options, true)沒用之后??梢栽囈幌孪旅娴姆椒ā?/p>
首先是在父組件中對數(shù)據(jù)進行請求,在賦值之前,先清空。
data里定義的三組echarts數(shù)據(jù)
在axios發(fā)送請求后
先清空再賦值。
補充知識:vue.js使用vue-echarts給柱形圖綁定點擊事件
我就廢話不多說了,大家還是直接看代碼吧~
<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中實現(xiàn)清除echarts上次保留的數(shù)據(jù)(親測有效)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關文章:
1. html中的form不提交(排除)某些input 原創(chuàng)2. ASP動態(tài)網(wǎng)頁制作技術經(jīng)驗分享3. vue使用moment如何將時間戳轉(zhuǎn)為標準日期時間格式4. jsp文件下載功能實現(xiàn)代碼5. 開發(fā)效率翻倍的Web API使用技巧6. ASP常用日期格式化函數(shù) FormatDate()7. js select支持手動輸入功能實現(xiàn)代碼8. CSS3中Transition屬性詳解以及示例分享9. asp.net core項目授權流程詳解10. CSS3實現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效
