0

我正在使用vue-dropzone组件。我想在文件预览上添加自定义按钮。我通过 ref 获取预览元素。我可以改变样式或其他任何东西。但是当我添加时<button>New Button</button>,它以字符串而不是 html 按钮的形式出现。我怎样才能做到这一点。您可以从下面的代码框链接复制。

代码沙盒链接

我怎样才能做到这一点?如果我能做到这一点,那么我将在那个按钮上添加 onClick 事件。

<template>
  <div>
    <vue-dropzone ref="myVueDropzone" id="dropzone" :options="dropzoneOptions"></vue-dropzone>
  </div>
</template>

<script>
import vue2Dropzone from "vue2-dropzone";
import "vue2-dropzone/dist/vue2Dropzone.min.css";

export default {
  name: "App",
  components: {
    vueDropzone: vue2Dropzone
  },
  mounted: function() {
    try {
      let mockFile = { name: "testfile.jpeg", size: 111 };
      this.$refs.myVueDropzone.manuallyAddFile(mockFile, "");
    } catch (err) {}

    const myElement = this.$refs.myVueDropzone.$el.querySelector(".dz-details");
    myElement.append("<button>New Button</button>");
  },
  data: function() {
    return {
      dropzoneOptions: {
        url: "https://httpbin.org/post",
        addRemoveLinks: true,
        dictRemoveFile: "Remove"
      }
    };
  }
};
</script>

<style>
</style>
4

1 回答 1

1

您可以使用 javascript 创建按钮,如下所示:

...
const myElement = this.$refs.myVueDropzone.$el.querySelector(".dz-details");
var button = document.createElement("button");
button.innerHTML  = "New Button";
myElement.appendChild(button);
...
于 2020-02-27T11:25:44.603 回答