L
L
Little Vasya2018-07-01 15:14:50
Vue.js
Little Vasya, 2018-07-01 15:14:50

Please explain about curly braces in Vuex?

I often notice curly braces in projects, what are they for? why without them?
And when are they used and when are they not?

const actions = {
  addToCart({ commit }, product){
    commit('addProduct', {
      id: product.id,
      price: product.price
    })
  },
  removeToCart({commit}, product){
    commit('removeProduct',  {
      id: product.id,
      price: product.price
    })
  }
}

const mutations = {
  addProduct(state, {id, price}) {
    const record = state.cart.find(p => p.id === id)

    if (!record) {
      state.cart.push({
        id,
        price,
        quantity: 1
      })
    } else {
      record.quantity++
    }
  },

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexey Shashenkov, 2018-07-01
@emilov

https://developer.mozilla.org/en/docs/Web/JavaScri...
https://developer.mozilla.org/en/docs/Web/JavaScri...

I
Ivan, 2018-07-01
@LiguidCool

This is packaging into objects. For example, to transfer several variables in one.

A
Anton P., 2018-07-02
@mrswylet

I can advise you to read these articles-lessons https://learn.javascript.ru/es-modern

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question