【问题标题】:How do I know if filepond is rendered?我怎么知道文件池是否被渲染?
【发布时间】:2022-01-05 17:22:20
【问题描述】:

我需要手动操作一些 DOM 属性(动态更改文件元素的样式)。我通过document.getElementById ("filepond - item-" + id) 搜索所需的元素。

但是,如果带有初始文件的 Filepond DOM 元素尚未呈现(getElementById() 未找到任何元素),我会遇到问题。

我目前正在用this.$NextTick()解决这个问题:

<template>
 <file-pond
    ref="filepond"
    :server="server"
    :files="files"
    @initfile.once="markMainImage"
  />
</template>
<script>
[...]
  methods: {
    async markMainImage () {
      await this. $ nextTick ();
      document.getElementById ("filepond - item-" + id).classList.add ("main-image");
    },
  },
</script>

但这不方便,也不是很可靠。 FilePond:loaded 事件是否可以用于此目的(https://pqina.nl/filepond/docs/api/instance/events/#filepond-loaded-event)?

如果是这样,你如何在 Vue 中使用它?

@loaded="markMainImage" 不会触发

或者是否有其他方法可以确定 filepond 是否使用初始文件呈现?

【问题讨论】:

  • 您可以使用addfile 事件或使用MutationObserver 来检测对DOM 的更改

标签: vue.js filepond


【解决方案1】:

感谢Rikcomment

@addfile.once="markMainImage"

有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-21
    • 2014-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-14
    相关资源
    最近更新 更多