There is too much code in a .vue file in vue component development. Is there any good solution?

how to break down components, there will be a lot of communication code between components, and the loss outweighs the gain, but in this way, there is too much code, which is difficult to maintain.

is there any good solution,

The

page has five pieces, which refer to each other and interact with each other. Is it too troublesome to split into components in this case? there is too much code for interaction between components

Mar.22,2021

there is too much interaction between components usually because the components are responsible for too many things, and the components are not so pure. There are five pieces in a page that interact with each other. It is recommended that these five pieces encapsulate separate ui components, separate the logic and put it in the parent component, and the parent component coordinates the interaction of the five blocks.


you can't have both fish and bear's paw

or subdivide the component through props , save props to the child component, and then trigger the operation data back to the parent component through emit .


first of all, you need to classify the components and adjust the structure.

it is recommended that components be divided into container components and presentation components. Container components carry data and presentation components, and data are passed to presentation components through properties.
that is, it needs to be structurally adjusted to parent-child components.

then you need to divide the responsibilities of each component

this needs to come according to your specific project.

finally, components communicate

the component is divided, so that's how the component communicates. Previously, there was no such problem in a component.
I think your scenario can be solved directly through parent-child data transfer (father passing son to father via props, child through event)

I hope my answer will be helpful to you.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e46158-44b7f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e46158-44b7f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?