<tfoot id='bZkqZ'></tfoot>
        <legend id='bZkqZ'><style id='bZkqZ'><dir id='bZkqZ'><q id='bZkqZ'></q></dir></style></legend>

      1. <small id='bZkqZ'></small><noframes id='bZkqZ'>

        <i id='bZkqZ'><tr id='bZkqZ'><dt id='bZkqZ'><q id='bZkqZ'><span id='bZkqZ'><b id='bZkqZ'><form id='bZkqZ'><ins id='bZkqZ'></ins><ul id='bZkqZ'></ul><sub id='bZkqZ'></sub></form><legend id='bZkqZ'></legend><bdo id='bZkqZ'><pre id='bZkqZ'><center id='bZkqZ'></center></pre></bdo></b><th id='bZkqZ'></th></span></q></dt></tr></i><div id='bZkqZ'><tfoot id='bZkqZ'></tfoot><dl id='bZkqZ'><fieldset id='bZkqZ'></fieldset></dl></div>
          <bdo id='bZkqZ'></bdo><ul id='bZkqZ'></ul>

        在 vuetify 中上传文件

        时间:2023-06-14
      2. <tfoot id='CDANb'></tfoot>
        • <bdo id='CDANb'></bdo><ul id='CDANb'></ul>
          <i id='CDANb'><tr id='CDANb'><dt id='CDANb'><q id='CDANb'><span id='CDANb'><b id='CDANb'><form id='CDANb'><ins id='CDANb'></ins><ul id='CDANb'></ul><sub id='CDANb'></sub></form><legend id='CDANb'></legend><bdo id='CDANb'><pre id='CDANb'><center id='CDANb'></center></pre></bdo></b><th id='CDANb'></th></span></q></dt></tr></i><div id='CDANb'><tfoot id='CDANb'></tfoot><dl id='CDANb'><fieldset id='CDANb'></fieldset></dl></div>

              <tbody id='CDANb'></tbody>

              • <small id='CDANb'></small><noframes id='CDANb'>

                <legend id='CDANb'><style id='CDANb'><dir id='CDANb'><q id='CDANb'></q></dir></style></legend>
                1. 本文介绍了在 vuetify 中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在 Vue.js 中为我的前端使用 Vuetify.js 组件,并希望创建一个带有文件上传的用户注册表单.我可以使用 v-text-field(一个 Vuetify 组件)创建表单.

                  I'm using Vuetify.js components for my front-end in Vue.js and want to create a user registration form with file upload. I'm able to create the form using v-text-field (a Vuetify component).

                  • 如何上传被选中(输入)的文件?
                  • 我应该使用哪个组件或有其他替代方法?

                  推荐答案

                  Vue JS 直到今天还没有文件输入功能,所以你可以调整 v-text-field 使其像图像输入字段一样工作.概念是,创建一个文件输入字段,然后使用 css 将其隐藏,并在 v-text-field 中添加一个事件以触发该特定文件输入字段以上传图像.我附上了片段,请玩一下,我也有一个使用 vue 和 vuetify 创建的小提琴,请访问 这里.谢谢!

                  Vue JS do not have file-input feature till today, so you can tweak v-text-field to work like image input field. The concept is, create an file input field and then hide it using css, and add an event in v-text-field to trigger that specific file input field to upload image. I have attached snippet please do play with that, and I also do have a fiddle created using vue and vuetify, visit here. Thanks!

                  new Vue({
                    el: '#app',
                    data: () => ({
                      title: "Image Upload",
                      dialog: false,
                      imageName: '',
                      imageUrl: '',
                      imageFile: ''
                    }),
                  
                    methods: {
                      pickFile() {
                        this.$refs.image.click()
                      },
                  
                      onFilePicked(e) {
                        const files = e.target.files
                        if (files[0] !== undefined) {
                          this.imageName = files[0].name
                          if (this.imageName.lastIndexOf('.') <= 0) {
                            return
                          }
                          const fr = new FileReader()
                          fr.readAsDataURL(files[0])
                          fr.addEventListener('load', () => {
                            this.imageUrl = fr.result
                            this.imageFile = files[0] // this is an image file that can be sent to server...
                          })
                        } else {
                          this.imageName = ''
                          this.imageFile = ''
                          this.imageUrl = ''
                        }
                      }
                    }
                  })

                  <link href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons' rel="stylesheet">
                  <link href="https://unpkg.com/vuetify/dist/vuetify.min.css" rel="stylesheet">
                  <div id="app">
                    <v-app>
                      <v-toolbar dark color="primary">
                        <v-toolbar-side-icon></v-toolbar-side-icon>
                        <v-toolbar-title class="white--text">{{ title }}</v-toolbar-title>
                        <v-spacer></v-spacer>
                        <v-btn icon @click="dialog = !dialog">
                          <v-icon>link</v-icon>
                        </v-btn>
                      </v-toolbar>
                      <v-content>
                        <v-container fluid>
                          <v-flex xs12 class="text-xs-center text-sm-center text-md-center text-lg-center">
                            <img :src="imageUrl" height="150" v-if="imageUrl"/>
                            <v-text-field label="Select Image" @click='pickFile' v-model='imageName' prepend-icon='attach_file'></v-text-field>
                            <input
                              type="file"
                              style="display: none"
                              ref="image"
                              accept="image/*"
                              @change="onFilePicked"
                            >
                          </v-flex>
                          <v-dialog v-model="dialog" max-width="290">
                            <v-card>
                              <v-card-title class="headline">Hello World!</v-card-title>
                              <v-card-text>
                                Image Upload Script in VUE JS
                                <hr>
                                Yubaraj Shrestha
                                <br>http://yubarajshrestha.com.np/
                              </v-card-text>
                              <v-card-actions>
                                <v-spacer></v-spacer>
                                <v-btn color="green darken-1" flat="flat" @click.native="dialog = false">Close</v-btn>
                              </v-card-actions>
                            </v-card>
                          </v-dialog>
                        </v-container>
                      </v-content>
                    </v-app>
                  </div>
                  <script src="https://unpkg.com/vue/dist/vue.js"></script>
                  <script src="https://unpkg.com/vuetify/dist/vuetify.js"></script>

                  最新版本 (V2.0.5) 在编辑这篇日期为 2019 年 8 月 11 日的帖子时,有一个专用的文件输入选项.请点击以下链接获取官方文档:https://vuetifyjs.com/en/components/file-输入.

                  Latest version (V2.0.5) while editing this post dated Aug 11, 2019, there's a dedicated file input option. Please follow the link below for official documentation: https://vuetifyjs.com/en/components/file-inputs.

                  这篇关于在 vuetify 中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无法编译现有项目,因为 Compass 找不到它 下一篇:调用后在 angularjs 中解绑 $watch

                  相关文章

                2. <tfoot id='xcP1F'></tfoot>
                3. <legend id='xcP1F'><style id='xcP1F'><dir id='xcP1F'><q id='xcP1F'></q></dir></style></legend>
                  • <bdo id='xcP1F'></bdo><ul id='xcP1F'></ul>
                4. <small id='xcP1F'></small><noframes id='xcP1F'>

                  1. <i id='xcP1F'><tr id='xcP1F'><dt id='xcP1F'><q id='xcP1F'><span id='xcP1F'><b id='xcP1F'><form id='xcP1F'><ins id='xcP1F'></ins><ul id='xcP1F'></ul><sub id='xcP1F'></sub></form><legend id='xcP1F'></legend><bdo id='xcP1F'><pre id='xcP1F'><center id='xcP1F'></center></pre></bdo></b><th id='xcP1F'></th></span></q></dt></tr></i><div id='xcP1F'><tfoot id='xcP1F'></tfoot><dl id='xcP1F'><fieldset id='xcP1F'></fieldset></dl></div>