javascript - 如何用 const 替换字符串的一部分?
问题描述
那是我的代码:
const searchTerm = `?term=${this.term}`;
const routeWithoutTerm = this.$route.fullPath.replace(searchTerm , '');
我想从中删除searchTerm
并将this.$route.fullPath
其保存在 中routeWithoutTerm
,但这显然是错误的方式。它只是代替任何东西。我怎样才能做到这一点?
编辑:让我们在执行时说,this.term = 'help'
我this.$route.fullPath = 'search/help?term=help'
想删除?term=help
解决方案
我终于找到了我的问题。
我有变音符号(ö,ä,ü),searchTerm
所以我必须encodeURI()
在我的searchTerm
第一个上使用。
推荐阅读
- oracle - 如何将纬度,经度(字符串)转换为坐标
- git - 如何记录使用旧路径重命名/移动的文件的整个 git 历史记录?
- systemd - 无论挂载点如何,systemd 可以在每次挂载后运行脚本吗?
- java - Maven 编译失败,没有迹象表明可能导致它的原因
- amazon-web-services - How to return less information from aws ec2 describe-instances
- python - Pip package won't run if I do not use sudo while installing it
- css - 如何将“位置:粘性”应用于弹性布局中的角材料卡?
- artifactory - 强制 Artifactory 在搜索时使用数值比较?
- c# - 我的客户端的“如果”语句被我的函数忽略,即使它成立
- java - 无论Java中的内容类型如何,如何将字段作为字符串获取?