天天看點

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)
    		...
    	}
    }
               

繼續閱讀