前端页面实时刷新数据,在axios请求中设置刷新频率

export default {
  name: 'home',
  data(){
    return {
      tj_datas:{
      notices:[],
      news:[], 
      real_time_datas:{
        ApiShop_count:0,
        UnReadNews_count:0,
        RunCase_count:0,
        Import_count:0
      },
    };
  },
  methods:{

  },
  components: {
    Menu,
  },
  // 进入页面先刷新请求数据
  mounted:function () {
    axios('http://localhost:8000/get_tj_datas/').then(res=>{
      this.tj_datas = res.data;
    });
     axios.get('http://localhost:8000/get_real_time_datas').then(res=>{
        this.real_time_datas = res.data;
    });

     // 刷新间隔,每1000毫秒刷新一次
    setInterval(()=>{
      axios.get('http://localhost:8000/get_real_time_datas').then(res=>{
        this.real_time_datas = res.data;
    }
      )},1000
    )
  }
}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐