vue datatables 实现动态刷新

在实现模态框动态刷新时遇到页面闪烁问题,原因是全量数据导致DataTable不断重绘。解决方案是通过Datatables API在刷新时先清空表格数据,再添加新获取的数据。具体操作包括使用`table.clear()`清空数据,避免使用`clear().draw()`以防止立即清除所有值,然后使用`rows.add(数组).draw()`添加并绘制新数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需求描述:最近需要写一个界面,主要功能是实现模态框的动态刷新

问题:可是涉及到自动刷新就有问题了,因为每次获取数据都是全量数据,用dataTable组装表格的话,页面会一直一直闪!里面绘制的表格会不断出现异常

如图这个是我做好的动态刷新,下面的请求是每隔5秒刷新一次,解决问题的主要方法如下(最终解决方法是在datatables的API 中找到的):

 

 
<template id="interface-statistics-modal" >
   <div class="modal fade" id="secondary-modal" data-toggle="modal" tabindex="-1" role="dialog" >
      <div class="modal-dialog  modal-lg" role="document">
         <div class="modal-content" >
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
               </button>
               <a class="pull-right help" >
                  <i class='fa fa-question-circle' ></i>
               </a>
               <h4 class="modal-title">{
  
  {title}}</h4>
            </div>
            <div class="modal-body">
               <table id="interface_statistics_table" class="table table-hover table-bordered table-striped">
                  <thead>
                  <tr>
                     <th>{
  
  {$t('slb.vs_name')}}</th>
                     <th>{
  
  {$t('slb.server_type')}}</th>
                     <th>{
  
  {$t('net.ip_address')}}</th>
                     <th>{
  
  {$t('net.status')}}</th>
                     <th>{
  
  {$t('slb.connect_number')}}</th>
                     <th>{
  
  {$t('slb.new_connect')}}</th>
                     <th>{
  
  {$t('slb.HTTP_request_rate')}}</th>
                     <th>{
  
  {$t('slb.request_flow')}}</th>
                     <th>{
  
  {$t('slb.response_flow')}}</th>
                  </tr>
                  </thead>
               </table>
            </div>
         </div>
      </div>
   </div>
</template>
<script>
    import tableMixin from '../../../mixins'
    import utils from '../../../utils.js'
    export default{
        mixins:[tableMixin],
        props:['statusData'],
        mounted:func
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值