elementPlus上传组件添加参数
时间: 2024-01-12 20:04:58 浏览: 178
在 ElementPlus 的上传组件中,你可以通过添加 props 属性来添加。以下是一些常用的 props:
1. action:上传的地址。
2. headers:设置上传的请求头部。
3. data:上传时附带的额外参数。
4. withCredentials:是否允许发送 cookie。
5. limit:上传文件数量限制。
6. accept:接受上传的文件类型。
7. beforeUpload:上传前的钩子函数。
例如,你想在上传时附带一个 token 参数,可以这样写:
```html
<el-upload
class="upload-demo"
action="/upload"
:headers="{ Authorization: `Bearer ${token}` }"
:data="{ key: 'value' }"
:with-credentials="true"
:limit="3"
accept=".png,.jpg"
:before-upload="beforeUpload">
<el-button slot="trigger">选取文件</el-button>
<el-button style="margin-left: 10px;" type="primary">上传文件</el-button>
</el-upload>
```
这里的 headers 属性会在上传时带上一个 Authorization 请求头部,data 属性会在上传时附带一个 key 值为 value 的额外参数。withCredentials 属性设为 true,表示允许发送 cookie。limit 属性设置为 3,表示最多上传 3 个文件。accept 属性设置为 .png 和 .jpg,表示仅接受这两种文件类型。beforeUpload 属性指定了上传前的钩子函数。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)