天天看点

element-ui 中手动上传文件

  • 代码如下
    <el-upload ref="upload" :auto-upload="false" :http-request="uploadWord">
    	<el-button size="small" type="primary">选择文件</el-button>
    </el-upload>
    
    <el-button size="small" type="primary" @click='upload'>点击上传</el-button>
               
  • 其中

    http-request

    中写具体的上传逻辑, 而该方法具体执行是放在

    upload

    的点击事件中
    methods:{
    	upload() {
    		// 其中 upload 对应的是上传组件中的 ref 的值, submit() 是固定的
    		this.$refs.upload.submit()
    	},
    	uploadWord(params) {
    		console.log(params.file)
    		...
    	}
    }
               

继续阅读