小编Alf*_*oad的帖子

Vue.js - 元素UI - 使用上传组件而不触发POST请求

我正在使用Element UI的上传组件.遗憾的是,一旦上传文件就会触发POST请求.我的目标是将文件推送到一个空数组,该数组将在按钮后发布.

HTML

// Element UI documentation says http-request overrides xhr behavior
// so I can use my own file request. In this case, I wanted to use a method
// though I'm not quite sure about this part?
<el-upload
     action="",
     :http-request="addAttachment",
     :on-remove="deleteAttachment",
     :file-list="attachments">
     <el-button size="mini" type="primary">Add file</el-button>
</el-upload>

// button that uploads the files here
Run Code Online (Sandbox Code Playgroud)

JS

data() {
     attachments: []
},

methods: {
     addAttachment ( file, fileList ) {
          this.attachments.push( file );
     },

     deleteAttachment () {
          // removes from …
Run Code Online (Sandbox Code Playgroud)

vue.js vue-component vuejs2

8
推荐指数
1
解决办法
7738
查看次数

标签 统计

vue-component ×1

vue.js ×1

vuejs2 ×1