那是我的代码:
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
答案 0 :(得分:0)
我终于找到了问题。
我的searchTerm
中有变音符(ö,ä,ü),所以我必须先在encodeURI()
上使用searchTerm
。
答案 1 :(得分:-1)
使用substring()函数获取所需零件,并使用replace()将其替换为所需零件
import React from "react";
const EyewearPurchaseBtn = (props) => (
<div>
<form className="eyewear-purchase-form" onSubmit={props.handleSubmit}>
<h3>Select Size</h3>
{
props.sizes.map( size => (
<div key={size} >
<input onChange={props.handleChange} className="radio-btn" type="radio" name="purchaseVal" value={size} />
<label className="eyewear-purchase-label">{size}</label><br/>
</div>
))
}
<button className="buy-now">Buy Now</button>
</form>
</div>
);
export default EyewearPurchaseBtn;