简体   繁体   English

等待元素加载然后渲染数据(vue.JS)

[英]Wait for the element to load and then render the data (vue.JS)

I am trying to put the v-show condition so that once the data is returned the graph is rendered and the data is filled in, but the graph is blank after the data is returned我正在尝试设置 v-show 条件,以便在返回数据后呈现图形并填充数据,但返回数据后图形为空白

my JS我的 JS

   methods: {
      refresh(){
         this.loading = true
         this.graf = false 

         this.$axios.get("/Op/Search")
         .then(res => { 
            this.loading = false;
            this.graf = true;    
            this.op = res.data 
            
            this.$refs.chartTypes.updateSeries([{
                name: 'TYPES',
                data: [this.op.cars, this.op.lines, this.op.cors]
             }])
         })
      }
   }
   data() {
      return {
         loading: true,
         graf: false,
      }
   }

my html我的 html

       <div class="col-7">
          <center v-show="loading" style="margin-top: 90px;"> <loading/> </center>
          <div v-show="graf">
              CARS
          </div>
          <div v-show="graf">
             <apexchart 
                ref="chartTypes"
                style="background: transparent;margin-left: -8px;"
                type="bar"  
                height="300" 
                :options="chartype" 
                :series="seriestypes"
                ></apexchart>
             </div>
       </div>

I think the data process faster than the rendering, how would you do once the request to the backend was processed, he would wait for the rendering component and then proceed to assemble the data?我觉得数据处理比渲染快,后端的请求处理完,他会等待渲染组件,然后进行数据的组装,你会怎么做?

Should actually work like this:实际上应该像这样工作:

<template>
   <div v-show="show">Test</div>
</template>

  .
  . 
  .
  methods: {
     makeCall(){
        this.$http.get('foo')
          .then(response => {
             this.show = true;
         });
     }
  },
  data: {
    show: false
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM