A
A
Andrey Vasilev2020-07-22 14:35:57
JavaScript
Andrey Vasilev, 2020-07-22 14:35:57

How to fix destructuring?

There is a list of cities that is taken from the storage

ul.cities-list
 li.cities-list__item(
 v-for="city in CITIES_LIST_MAIN"
 @click="selectCity"
 v-bind="cityChoiceBinds"
 )
 | {{city.name}}


There is a bind: We sort through
the object of the cities that came to us and return:
cityChoiceBinds() {
 this.CITIES_LIST_MAIN.map((item) => {
  return item
 })
}


On the click of a city, it works:
selectCity(e, { cityCode, storeId, name }) {
 this.CHANGE_CITY({
  cityCode,
  storeId,
  name,
 })
},


In object which arrives from a getter CITIES_LIST_MAIN
All these properties are. Maybe the logic is different? Or am I stuck?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-07-22
@Nolis

@click="selectCity"

selectCity(e, { cityCode, storeId, name }) {

And what are you going to destructure something? - CITIES_LIST_MAIN elements are not passed to the function. Must be passed on. And the event object is not needed, it is not used in selectCity, so we remove it from the list of parameters (but if it is suddenly needed in the future, it is available in the template as $event):
@click="selectCity(city)"
selectCity({ cityCode, storeId, name }) {
  ...

A
Alexey Ukolov, 2020-07-22
@alexey-m-ukolov

The cityChoiceBinds() function doesn't return anything, and map doesn't make sense in it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question