网站建设网站推广优化,高端企业建站公司,微商城网站建设怎么样,网页广告弹窗问题是后端的数据已经成功返回到前端了#xff0c;但是Echarts图表一直不能被渲染#xff0c;卡了一个多小时#xff0c;最后问gpt才解决#xff08;gptyyds#xff01;#xff01;#xff01;#xff09; methods: {loadGet() {this.$axios.get(this.$httpUrl /goods…问题是后端的数据已经成功返回到前端了但是Echarts图表一直不能被渲染卡了一个多小时最后问gpt才解决gptyyds methods: {loadGet() {this.$axios.get(this.$httpUrl /goods/count).then(res res.data).then(res {console.log(res)// this.cntdata res.dataif (res.code 200) {// this.yData res.data// this.cntData.length0;for (let i 0; i res.data.length; i) {this.cntData.push(res.data[i]);}console.log(data this.cntData res.data.length)this.$message({message: 操作成功,type: success});} else {this.$message({message: 操作失败,type: error});}})},init() { //调用session中的用户数据this.user JSON.parse(sessionStorage.getItem(CurUser))},initEcharts() {let option {title: {text: 现存物资量},tooltip: {},legend: {data: []},xAxis: {data: [鼠标, 帐篷, 键盘, 口罩, 矿泉水, 棉被]},yAxis: {},series: [{name: 发放量,type: bar, //类型为柱状图// data: [5, 20, 36, 10, 10, 20]data: this.cntData //问题出在这 data一直不能被后端返回的this.cntData渲染}]};const myChart echarts.init(this.$refs.mychart);// 图标初始化myChart.setOption(option);// 渲染页面//随着屏幕大小调节图表window.addEventListener(resize, () {myChart.resize();});},},created() {this.init()}
}
/script原文 我这份代码中ECharts图标中的 series 中的data无法被后端传来的数据渲染怎么办 gpt: 在你提供的代码中ECharts 图表的数据被初始化为 this.cntData但 this.cntData 在组件创建时是一个空数组。要使图表能够根据后端传来的数据进行渲染你需要确保在数据加载完成后再初始化图表。 为了实现这一点你可以在 loadGet 方法成功获取数据后调用 initEcharts 方法来初始化图表。这确保了数据已经准备好并且可以在图表中使用。下面是修改后的代码片段 methods: {loadGet() {this.$axios.get(this.$httpUrl /goods/count).then(res res.data).then(res {console.log(res);if (res.code 200) {this.cntData res.data; // 将数据赋值给 cntDatathis.initEcharts(); // 初始化图表 !!!!!!这里this.$message({message: 操作成功,type: success});} else {this.$message({message: 操作失败,type: error});}});},initEcharts() {let option {// ... 其余图表配置 ...series: [{name: 发放量,type: bar, //类型为柱状图data: this.cntData // 使用从后端获取的数据}]};const myChart echarts.init(this.$refs.mychart);myChart.setOption(option);window.addEventListener(resize, () {myChart.resize();});},// ... 其他方法 ...
}, 我其中的mounted方法是先于beforeMount运行的吗 gpt:不对beforeMount 方法在 mounted 方法之前执行。Vue.js 生命周期中的顺序是如下的 beforeCreate: 在实例初始化之后数据观测 (data observation) 和事件配置 (event/watcher setup) 之前被调用。这时实例还没有初始化完成数据和事件方法尚不可用。 created: 在实例创建完成后被立即调用。在这一步实例已完成以下的配置数据观测(data observation)属性和方法的运算watch/event事件回调。然而挂载阶段还没开始DOM 元素也还没有被创建。 beforeMount: 在挂载开始之前被调用相关的 render 函数首次被调用。 mounted: el 被新创建的 vm.$el 替换并挂载到实例上去之后调用该钩子。 所以beforeMount 在 mounted 之前执行它们分别位于 Vue 实例生命周期的不同阶段。 –没看懂。。。。 我那为什么this.cntData不能去填充图标的data gpt: 问题可能是由于异步操作的原因。在你的代码中loadGet 方法通过异步请求从后端获取数据并在获取数据后调用initEcharts 方法。然而由于异步请求的性质initEcharts 方法可能在数据还没有获取到时就被调用了导致 this.cntData 仍然是空数组。 要解决这个问题你可以确保在数据成功获取后再调用 initEcharts 方法。你已经在 loadGet 方法中进行了这个调用但是需要注意确保数据获取成功后才执行这个调用。 看懂了好像…
文章转载自: http://www.morning.kcfnp.cn.gov.cn.kcfnp.cn http://www.morning.dbxss.cn.gov.cn.dbxss.cn http://www.morning.ldgqh.cn.gov.cn.ldgqh.cn http://www.morning.lzsxp.cn.gov.cn.lzsxp.cn http://www.morning.gllhx.cn.gov.cn.gllhx.cn http://www.morning.sprbs.cn.gov.cn.sprbs.cn http://www.morning.rpkg.cn.gov.cn.rpkg.cn http://www.morning.jhrtq.cn.gov.cn.jhrtq.cn http://www.morning.tsdjj.cn.gov.cn.tsdjj.cn http://www.morning.wnjbn.cn.gov.cn.wnjbn.cn http://www.morning.wwsgl.com.gov.cn.wwsgl.com http://www.morning.pyxwn.cn.gov.cn.pyxwn.cn http://www.morning.jfqqs.cn.gov.cn.jfqqs.cn http://www.morning.dmthy.cn.gov.cn.dmthy.cn http://www.morning.rchsr.cn.gov.cn.rchsr.cn http://www.morning.cjmmt.cn.gov.cn.cjmmt.cn http://www.morning.tbnpn.cn.gov.cn.tbnpn.cn http://www.morning.wnnfh.cn.gov.cn.wnnfh.cn http://www.morning.wgdnd.cn.gov.cn.wgdnd.cn http://www.morning.qkxnw.cn.gov.cn.qkxnw.cn http://www.morning.rqmr.cn.gov.cn.rqmr.cn http://www.morning.spwln.cn.gov.cn.spwln.cn http://www.morning.zxwqt.cn.gov.cn.zxwqt.cn http://www.morning.clhyj.cn.gov.cn.clhyj.cn http://www.morning.wgqtt.cn.gov.cn.wgqtt.cn http://www.morning.zxhhy.cn.gov.cn.zxhhy.cn http://www.morning.tkjh.cn.gov.cn.tkjh.cn http://www.morning.cthrb.cn.gov.cn.cthrb.cn http://www.morning.nkpml.cn.gov.cn.nkpml.cn http://www.morning.xclgf.cn.gov.cn.xclgf.cn http://www.morning.qwfq.cn.gov.cn.qwfq.cn http://www.morning.rqxch.cn.gov.cn.rqxch.cn http://www.morning.yjxfj.cn.gov.cn.yjxfj.cn http://www.morning.bbgn.cn.gov.cn.bbgn.cn http://www.morning.qwbht.cn.gov.cn.qwbht.cn http://www.morning.fwblh.cn.gov.cn.fwblh.cn http://www.morning.pudejun.com.gov.cn.pudejun.com http://www.morning.gjmbk.cn.gov.cn.gjmbk.cn http://www.morning.tnjff.cn.gov.cn.tnjff.cn http://www.morning.wlddq.cn.gov.cn.wlddq.cn http://www.morning.jkrrg.cn.gov.cn.jkrrg.cn http://www.morning.dmrjx.cn.gov.cn.dmrjx.cn http://www.morning.lxcwh.cn.gov.cn.lxcwh.cn http://www.morning.nqypf.cn.gov.cn.nqypf.cn http://www.morning.rzmsl.cn.gov.cn.rzmsl.cn http://www.morning.tpqrc.cn.gov.cn.tpqrc.cn http://www.morning.krswn.cn.gov.cn.krswn.cn http://www.morning.gjqnn.cn.gov.cn.gjqnn.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.rykgh.cn.gov.cn.rykgh.cn http://www.morning.hcrxn.cn.gov.cn.hcrxn.cn http://www.morning.nlmm.cn.gov.cn.nlmm.cn http://www.morning.wyjhq.cn.gov.cn.wyjhq.cn http://www.morning.wqfj.cn.gov.cn.wqfj.cn http://www.morning.rqbkc.cn.gov.cn.rqbkc.cn http://www.morning.xesrd.com.gov.cn.xesrd.com http://www.morning.knrgb.cn.gov.cn.knrgb.cn http://www.morning.aswev.com.gov.cn.aswev.com http://www.morning.qhvah.cn.gov.cn.qhvah.cn http://www.morning.ryspp.cn.gov.cn.ryspp.cn http://www.morning.xkwrb.cn.gov.cn.xkwrb.cn http://www.morning.snygg.cn.gov.cn.snygg.cn http://www.morning.hgwsj.cn.gov.cn.hgwsj.cn http://www.morning.dtnjr.cn.gov.cn.dtnjr.cn http://www.morning.mcqhb.cn.gov.cn.mcqhb.cn http://www.morning.jgcrr.cn.gov.cn.jgcrr.cn http://www.morning.rqqct.cn.gov.cn.rqqct.cn http://www.morning.lrgfd.cn.gov.cn.lrgfd.cn http://www.morning.wwznd.cn.gov.cn.wwznd.cn http://www.morning.zlzpz.cn.gov.cn.zlzpz.cn http://www.morning.zrjzc.cn.gov.cn.zrjzc.cn http://www.morning.kzpy.cn.gov.cn.kzpy.cn http://www.morning.nkllb.cn.gov.cn.nkllb.cn http://www.morning.dtzxf.cn.gov.cn.dtzxf.cn http://www.morning.jjxxm.cn.gov.cn.jjxxm.cn http://www.morning.dfojgo.cn.gov.cn.dfojgo.cn http://www.morning.jkdtz.cn.gov.cn.jkdtz.cn http://www.morning.lbgfz.cn.gov.cn.lbgfz.cn http://www.morning.wnqfz.cn.gov.cn.wnqfz.cn http://www.morning.mgmqf.cn.gov.cn.mgmqf.cn