You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Vueform中配置Authorization: Bearer请求头并扩展组件代码?

在Vueform中配置Bearer授权请求头的两种方法

方法1:直接使用headers属性

Vueform组件支持通过headers属性直接设置请求头,适用于仅需添加授权头的简单场景:

<Vueform 
  endpoint="https://xxxxx.xx/xxxxx" 
  method="post"
  :headers="{
    'Authorization': 'Bearer xxxxx'
  }"
>
<!-- 表单内容 -->
</Vueform>

如果你的token是动态获取的(比如存在localStorage或状态管理中),可以通过模板字符串动态拼接:

<Vueform 
  endpoint="https://xxxxx.xx/xxxxx" 
  method="post"
  :headers="{
    'Authorization': `Bearer ${localStorage.getItem('authToken')}`
  }"
>
<!-- 表单内容 -->
</Vueform>

方法2:使用request-options属性

如果需要配置更多Axios请求选项(超时、拦截器等),可以用request-options传入完整的请求配置对象,其中包含headers字段:

<Vueform 
  endpoint="https://xxxxx.xx/xxxxx" 
  method="post"
  :request-options="{
    headers: {
      'Authorization': 'Bearer xxxxx'
    },
    timeout: 5000 // 额外配置示例:超时时间
  }"
>
<!-- 表单内容 -->
</Vueform>

内容的提问来源于stack exchange,提问作者Naga Vijayapuram

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 11:47:07