vue.js - 为 Vuetify v-file-input 提供初始文件名值

标签 vue.js vuetify.js

我的模板中有这个 html:

        <v-file-input
          :label="label"
          accept="image/*"
          prepend-icon="mdi-camera"
          @change="uploadImage"
          hide-details
          outlined
        />

我的组件还有一个名为 current 的 Prop 它包含一个文本,它是当前文件的名称。

当组件显示时 v-file-input为空,但我希望它包含当前文件名的名称。我试过 :value="current"v-model="current"无济于事。

我该怎么办?

最佳答案

您可以使用 value支柱。但它不接受字符串。从文档:

value - A single or array of File objects



因此,例如这有效:

data() {
    return {
      current: new File(["foo"], "foo.txt", {
                  type: "text/plain",
                })
    }
  }

<v-file-input label="File input" :value="current" ></v-file-input>

这样做是否是个好主意是不同的问题:) 你知道,你拥有的不仅仅是文件名,它包括内容在内的整个文件。如果用户像这样提交您的表单怎么办?也支持 File() constructor不是那么好......例如在Edge上不起作用......

关于vue.js - 为 Vuetify v-file-input 提供初始文件名值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59446013/

相关文章:

vue.js - 使用 Vuetify v-btn 和 Vue 路由器在新窗口中打开链接

javascript - Vuejs动态创建元素添加鼠标事件

vue.js - 如何使用 Vue.js 和 Vuelidate 验证模糊字段

javascript - 评估注入(inject)了 v-html 的 HTML

vue.js - Vuetify 样式不可见

vue.js - 无法导航到嵌套路由,但浏览器 URL 已更新

vue.js - Vuetify 上的 Eslint : Variable 'props' is already declared in the upper scope

javascript - Vuetify 数据表在列单击时展开行

vue.js - 如何通过仅提及父目录名称而不是文件名来导入 index.vue?

javascript - Vue 路由参数在 @change 事件发生变化但组件不受影响