N
N
Nurseit Sharip2018-12-21 12:16:59
Vue.js
Nurseit Sharip, 2018-12-21 12:16:59

How to organize a shopping cart on VueJS, Vuex?

Hello, I'm new to Vue. I just can not organize how to make a basket of goods.
5c1caeccf1998837196460.png
There is such a layout.
I have an array of products:

<script>
        const product = (NameProduct, PriceProduct, DescProdusct, img) => ({NameProduct, PriceProduct, DescProdusct, img})
        const products = [
      product('name1', '130', 'desc1', 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/FD_1.jpg/267px-FD_1.jpg'),
      product('name2', '130', 'desc2', 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/FD_1.jpg/267px-FD_1.jpg'),
      product('name3', '130', 'desc3', 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/FD_1.jpg/267px-FD_1.jpg'),
      product('name4', '130', 'desc4', 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1f/FD_1.jpg/267px-FD_1.jpg')
    ];

export default {
      data: () => ({
      products: products
})
    </script>

By click:
<v-btn 
                        flat
                        small 
                        class="black--text"
                        @click="add"
                      >
                        В корзину
                      </v-btn>

it is necessary to transfer the goods, let's say to the cards[] array, the goods, when clicking on add a second time, multiply only the quantities and not give the new card a new index. They advised to do with Vuex so that the goods are stored when the page is updated.
Can you please tell me how can I do this with Vuex?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Sedyshev, 2018-12-21
@NurseitSharip

Surprisingly, in the official repository there is an example directly about this.
There is also a course for beginners based on this example.
And all about the grocery basket! Joy happiness!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question