Axios - How Can I Encode the Injected Value In My Get() Request?

Viewed 136

I've got an axios call in my Vue app that's failing:

axios.get(`parts/${item.number}`)
   .then(response => { /* do things */ });

...because sometimes the item.number contains a / …not good to have extras of those in a URL. What's the recommended way to HTML encode that item.number?

1 Answers

Use encodeURIComponent to encode such parts of URL:

Example

// in browser console
encodeURIComponent('aaa/ddd')
"aaa%2Fddd"
Related