我如何在axios请求中的此URL(http:// localhost:3001 / products / 2)中在此处使用数字2 ...
const getProd = () => {
axios.get(`http://localhost:3000/customer/product/${I want to take the number from the url and use it here}`)
.then((result) => {
setProducts(result.data);
return
})
}
尝试这个
window.location.href.split('').pop();
如果网址的ID超过1个数字(例如-1212)
window.location.href.split('/').pop();
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句