vue el-upload 例子
时间: 2023-11-06 10:57:00 浏览: 94
【JavaScript源代码】vue el-upload上传文件的示例代码.docx
Vue的el-upload组件用于文件上传,下面是一个el-upload的例子:
```html
<template>
<div>
<el-upload action="http://127.0.0.1:8702/Hello/upload" :on-change="upload" :limit="1" :auto-upload="false">
<div>文件上传</div>
</el-upload>
</div>
</template>
<script type="text/javascript">
import $ from 'jquery'
export default {
data () {
return {
mgs: ''
}
},
methods: {
getTest1 () {
console.info('1212')
this.$emit('refresh')
},
upload (file) {
debugger
console.info(file)
let form = new FormData()
form.append('file', file.raw)
let reader = new FileReader()
reader.onload = function () {
$.ajax({
url: 'http://127.0.0.1:8702/Hello/upload',
type: 'post',
data: form,
processData: false,
contentType: false,
success: function () {
console.info('上传成功')
}
})
}
reader.readAsBinaryString(file.raw)
}
}
}
</script>
```
阅读全文