[Vuejs]-String's split method shows undefined

1πŸ‘

βœ…

Here is what you want:

let url = "foo=bar";
console.log(typeof (url)) // outputs string

let status = url => url.split('=')[1]

console.log(status(url));// "bar"

0πŸ‘

I think your this.$route.query.item does not contain = character. if you are looking for current url try this may be

let url = this.$router.currentRoute;
console.log(url); // check if this is the url you expect
let status = 'url does not contain = char';
if(url.includes('='){
   status = url.split('=')[1];
}
console.log(status);

note: if you actually need to split this.$route.query.item, console log it and check if it contains = or perhaps add a check for it.

Leave a comment