1

I have a method like this which is called on click, 2 params are passed:

 selectOption(variantName, value) {
  this.$router.push({ query: { variantName: value } })
}

If I call selectOption with variantName = "size", and value ="small"

I want the url to be something like /foo?size=small

at the moment it is something like ?variantName=size

1 Answer 1

2

Since the key is dynamic you could wrap it by [] like :

 this.$router.push({ query: { [variantName]: value } })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.