当前项目Ant Design of Vue —— Upload组件上传图片,要上传token的写法

在 a-upload中加上:headers=“headers”

1
2
3
4
5
6
7
8
9
10
11
       <a-upload
:action=”this.$baseURL+’/image/upload'”
:headers=”headers”
:beforeUpload=”beforeUpload”
:multiple=”true”
:file-list=”fileList”
@change=”handleChange”
>
<a-button class=”upbtn”> <a-icon type=”upload” /> Upload </a-button>
<div style=”font-size: 12px;color: #8392A7;margin-top: 16px;”>图标最大尺寸为180*52比例,大小不能超过20M</div>
</a-upload>

然后在data中添加代码如下
this.$store.state.user.token(该项目通过vuex取的,具体项目按照自己的vuex写法取得)

1
2
3
4
5
  headers: {
‘Access-Token-PC’: this.$store.state.user.token,
//   ‘Authentication’: this.$store.state.user.token,
// ‘Content-Type’: ‘application/json’
},

注:每个后端的传递方式不一样,所以不要照抄。

原文链接:https://doubaoyuanma.com/blog/%e5%bd%93%e5%89%8d%e9%a1%b9%e7%9b%aeant-design-of-vue-upload%e7%bb%84%e4%bb%b6%e4%b8%8a%e4%bc%a0%e5%9b%be%e7%89%87%ef%bc%8c%e8%a6%81%e4%b8%8a%e4%bc%a0token%e7%9a%84%e5%86%99,转载请注明出处。

0

评论0

显示验证码
没有账号? 注册  忘记密码?