【问题标题】:unnecessary %E2%80%8B added in the urlurl 中添加了不必要的 %E2%80%8B
【发布时间】:2021-01-31 13:48:13
【问题描述】:

我在 axios.create() 方法中设置了我的基本 URL,并在其他页面中使用它。但它在 URL 中添加了不必要的“%E2%80%8B”。有没有办法避免这个问题? 这是我的代码块:

import axios from 'axios';

const apiVersion = 1;
export const baseURL = ('https://localhost:50001')

export default axios.create({
  baseURL: baseURL,
});

export const urls = {
    unit: {
    get_all: `/​api/v${apiVersion}/Unit/get-all-units`,
    get_by_key: `api/v${apiVersion}ion}/Unit/get-unit`,
    post: `/api/v${apiVersion}/Unit/save-unit`,
    put: `/api/v${apiVersion}/Unit/update-unit`,
    delete: `​/api​/v${apiVersion}​/Unit​/delete-unit​`
  }
}

这个 axios 我打算以这种方式使用我的另一个组件:

const getAllUnits = async () => {
    try {
      await axios
        .get(urls.unit.get_all)
        .then(res => {
          setRecords(res.data.data);
          setIsLoaded(true)
        })
    } catch (e) {
      console.log(e);
    }
  }

但它显示此错误。请帮帮我。enter image description here

【问题讨论】:

标签: reactjs


【解决方案1】:

您的模板字符串中有一个不可见的字符,称为“零宽度空间”(see this table)。您可能不小心插入了它或从其他地方复制了它。尝试完全删除并重新键入模板字符串以确保您摆脱它。

【讨论】:

  • 谢谢。我发现了我的问题。但有什么解决办法吗?我有很多网址。手动输入这个很烦人
  • 您可以尝试将代码粘贴到一个简单的文本编辑器(如记事本,如果您在 Windows 上),然后将其粘贴回您的代码编辑器。您还可以尝试使用代码编辑器进行查找和替换:复制有问题的字符串的开头(“替换”字段中的“api", including the backtick), paste it into the "find" field, then type in "api”。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-31
  • 1970-01-01
  • 2011-09-03
  • 2017-11-08
  • 2019-02-03
  • 2015-12-24
  • 2014-02-23
相关资源
最近更新 更多