前端页面实时刷新数据,在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

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐