2

I wanna make url with choosen settings

const settings = this.getSettings();//returns object
Object.entries(settings).forEach(([key, value]) => {
       this.$router.push({ query: { ...this.$route.query, key: value } }); //why i can't access key here?
});
1
  • The "key" in forEach table argument is a variable, while the "key" inside the object below is an object property named "key" Commented Dec 29, 2020 at 13:56

2 Answers 2

2

You should wrap the key by [] accessor :

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

Comments

1

just a guess: "key" in query: { ...this.$route.query, key: value } will be treated as a string, i guess you want the "key" variable to be used instead.

var query = { ...this.$route.query };
query[key] = value;
this.$router.push({ query: query });

but then i also suspect that you want all key/values in the url? so you'll have to restructure..

const settings = this.getSettings();
this.$router.push({ query: { ...this.$route.query, ...settings }});

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.