【问题标题】:Axios - How Can I Encode the Injected Value In My Get() Request?Axios - 如何在我的 Get() 请求中编码注入的值?
【发布时间】:2020-05-11 16:26:40
【问题描述】:

我的 Vue 应用程序中有一个 axios 调用失败:

axios.get(`parts/${item.number}`)
   .then(response => { /* do things */ });

...因为有时item.number 包含/ ...在 URL 中包含这些内容并不好。对item.number 进行 HTML 编码的推荐方法是什么?

【问题讨论】:

  • 推荐的方式是使用encodeURIComponent,顾名思义。这取决于后端如何处理 url。

标签: vue.js axios


【解决方案1】:

使用 encodeURIComponent 对 URL 的这些部分进行编码:

例子

// in browser console
encodeURIComponent('aaa/ddd')
"aaa%2Fddd"

【讨论】:

    猜你喜欢
    • 2020-04-17
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 2021-08-01
    • 2016-12-31
    • 2020-02-14
    • 2021-04-10
    • 1970-01-01
    相关资源
    最近更新 更多