V
V
VegasChickiChicki2019-06-14 22:18:18
Vue.js
VegasChickiChicki, 2019-06-14 22:18:18

How to tell Vue where and when to re-render a component?

I started to study Vue and therefore I have little experience, so as not to write crutches for a truck, I would like to ask for help, understand the logic of this task, and the task is as follows:
The user clicks on the button -> the request is sent to the server -> the function is executed there and enters data into JSON file -> further after the JSON has changed, you need to redraw the page based on what has changed.
I have 2 main questions when Vue should do this, because first the data must be updated in JSON, and this will happen only after the server writes it there, I suppose there must be some kind of asynchronous functions, and the second question is how to specify Vue what exactly to redraw, since a lot of different data is taken from this JSON file, and only those that have been updated will need to be redrawn.
PS If possible, some code example, thanks!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2019-06-15
@UPSA

As a beginner, I can assume ... something like an answer. )))

a function is executed there and enters data into a JSON file
I imagine everything is not much wrong. I separate the transfer of data to the server and the transfer of data from the server. If I need to save data, I form a request to the server to transfer data. The controller on the server checks the data that cannot be checked on the client side, if the data is checked, then the data must be returned and redrawn. These are 2 different "JSON". These are 2 different functions. Sending and receiving.
and it will be necessary to redraw only those that have been updated.
No need to torture the server by sending it arrays. Track only 1 (single): field, checkbox, list... button (like a checkbox). Changed - save. For example, You have a product, each click of the "Checkmark" (or button) transfers the product id to the "basket" to the server. If the server returned TRUE, then you need to redraw the DOM object "Basket", increasing the counter of the number of goods by 1. But on the "Basket" page there is only 1 button, for example, close and create an invoice, the data about the product in the basket is already saved on the server, they do not need to be re-written, in theory it is only necessary to send 1 field (true).
This is followed by nodejs and vue.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question