- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 React.js 组件的 componentWillMount() 中使用此函数。但浏览器说 window.decodeURIComponent(...) 不是一个函数,我不明白。谁能告诉我如何让它发挥作用?谢谢
export const getUrlQuery = window => {
let queryDict = {}
if (window.location.search) {
window.location.search.substr(1).split("&").forEach((item) => {
let s = item.split("=")
let key = s[0]
let value = s[1] && window.decodeURIComponent(s[1])
(queryDict[key] = queryDict[key] || []).push(value)
})
}
return queryDict
}
最佳答案
有趣的错误,原来 let value = ..
行被解析为
let value = s[1] && window.decodeURIComponent(s[1])(queryDict[key] = queryDict[key] || []) ..
换句话说,您将括号表达式应用于 window.decodeURIComponent(s[1])
的结果,该结果是字符串而不是函数。您可以使用明确的分号来修复它(这通常不是一个坏主意):
let value = s[1] && window.decodeURIComponent(s[1]);
UPD:看看代码在做什么,您可能会对 qs 感兴趣。 npm 包。
关于javascript - 解码URIComponent不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49179035/
var frank_param = gup( 'frank' ); var pageURL = encodeURIComponent("directory_doctor_page.php?Doctor
由于 msdn 仅提供了部分概述(如 here 所示),并且我一直在寻找完整的示例,因此我将在这里分享答案。 最佳答案 这段代码的结果 var uri = new Uri("https
我正在使用 WebLogic 10.2c。我的包含 jax-rs 资源的 web 应用程序在 grizzley 中工作正常,但是当它根据 http://docs.oracle.com/cd/E1790
我有一个 Javascript 小书签,它使用 encodeURIcomponent 将当前页面的 URL 传递给服务器端,然后在服务器端使用 urldecode 获取字符回来。 问题是,当编码字符不
我想要我的 REST 客户端,使用 Spring Web 的 RestTemplate ,对 URL 参数中的所有特殊字符进行 % 编码,而不仅仅是非法字符。 Spring Web's documen
我是一名优秀的程序员,十分优秀!