我正在使用vutify+nuxt创建我的Web应用程序,如果单元格的值发生变化,我如何将动画应用到单元格?

I tried to add a ref to my table element like:
<v-data-table ref="table" :items="data" :headers="headers"/>

然后

$this.$refs.table.$el.addEventListener('change', func)

但什么都没发生...有谁能开个灯吗?

推荐答案

超过"value"个我相信你会对TD手机"textContent"的变化感兴趣.

The best would be tap in the function that does the content update.
Otherwise, use MutationObserver on the childList property for every TD of a specific table:

const contentsObserver = new MutationObserver((mutations) => {
  mutations.forEach(mu => {
    if (mu.type === "childList") {
      mu.target.classList.add("is-changed");
      mu.target.addEventListener("animationend", () => {
        mu.target.classList.remove("is-changed");
      }, {once: true});
    }
  });
});

const elsTD = document.querySelectorAll("tbody td");
elsTD.forEach(elTD => contentsObserver.observe(elTD, {childList: true}));


// Demo: dynamic textContent change
const rand = (min, max) => Math.random() * (max - min) + min;
const changeText = () => {
  const index = ~~rand(0, elsTD.length);
  const elTDActive = elsTD[index];
  elTDActive.textContent = rand(1, 99).toFixed(2);
  setTimeout(changeText, rand(300, 1300));
}
changeText();
td, th {
  padding: 0.5rem 1rem;
  font: 1rem/1.5 monospace;
}

.is-changed {
  animation: blink 1s;
}

@keyframes blink {
  0% {
    background: fuchsia;
  }
}
<table>
  <thead>
    <tr>
      <th></th>
      <th>Foo</th>
      <th>Bar</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>Baz</th>
      <td>23.00</td>
      <td>56.45</td>
    </tr>
    <tr>
      <th>Daz</th>
      <td>34.46</td>
      <td>89,20</td>
    </tr>
  </tbody>
</table>

Javascript相关问答推荐

Codemirsor 6语言包的使用部分是什么?

更新Reduxstore 中的状态变量,导致整个应用程序出现不必要的重新渲染

获取加载失败:获取[.]添加时try 将文档添加到Firerestore,Nuxt 3

yarn安装一个本地npm包,以便本地包使用main项目的node_modules(ckeditor-duplicated-modules错误)

MongoDB中的引用

如何在Connect 4游戏中 for each 玩家使用位板寻找7形状?

Phaser 3 console. log()特定游戏角色的瓷砖属性

如何在mongoose中链接两个模型?

在react js中使用react—router—dom中的Link组件,分配的右侧不能被 destruct ''

无法读取未定义错误的属性路径名''

编剧如何获得一个div内的所有链接,然后判断每个链接是否都会得到200?

如何在Angular17 APP中全局设置AXIOS

Next.js服务器端组件请求,如何发送我的cookie token?

第二次更新文本输入字段后,Reaction崩溃

为什么这个.add.group({})在教程中运行得很好,但在我的游戏中就不行了?

使用带有HostBinding的Angular 信号来更新样式?

如何利用CSS中的隐藏元素实现平滑扩展和防止网格行间隙

使用类型:assets资源 /资源&时,webpack的配置对象&无效

在表单集中保存更改时删除';禁用';

ReferenceError:无法在初始化之前访问setData