I'm trying to achieve this with object destructuring but can't quite figure out the right syntax:
Without destructuring:
this.$store.dispatch('user/login', {
username: this.username,
password: this.password
})
With destructuring (doesnt work):
this.$store.dispatch('user/login', {
{ username, password } = this
})
What's the right syntax here?
I think you're confused. There is nothing to "destructure" here - your dispatch
function simply takes an object parameter with 2 properties ( username
and password
).
You could define this object before calling it like:
var input = {username:this.username,password:this.password};
this.$store.dispatch('user/login', input);
Or, as your current object has the right properties you could simply pass this
this.$store.dispatch('user/login', this);
It's worth going though the docs here on destructuring to understand it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.