首页 > 解决方案 > 如何用 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

标签: javascriptvue.js

解决方案


我终于找到了我的问题。

我有变音符号(ö,ä,ü),searchTerm所以我必须encodeURI()在我的searchTerm第一个上使用。


推荐阅读