How to encapsulate your own functional components according to business

query echoing input seal

recently had the opportunity to do a management system uses a vue + element-ui, the form page is very large, and are surprisingly large, and more page development time to expand the advantages and disadvantages of the form I’d probably say something first, our task is now based tools to make him more concise, the function is not bad, but also conducive to the development, maintenance,

directly into the the question

function like this:

form a common input function is to bind a button that when I click the button, pop-up query box, which has a small list of found data after the return to significant point line, very simple needs, but there will be a large number of application site, so certainly can not copy and paste, the input box every time we can write, but pop up a small query if each form, each individual bomb box again repeat wrote in trouble, but if we raise it a lot easier on us, through the data to the control function

如何根据业务封装自己的功能组件

some people may think that is nonsense, and on such a simple thing, it is necessary to write so much (I’ve tried to put my mind to say it, manual funny)

to do this is a small list of queries, do we sort out things to do first planning to write code without writing at the side change, or make more and more difficult, writes the following should not have found that the above write, go change and lazy to change, and then depressed with reluctance submitted go up, although the function but they looked at all ……

1 demand analysis:? we need what elements

  1. a single form, a Table, page (layout)
  2. b. n block condition, query button, reset button, other function buttons (form internal)

we know by the sorting element, there are several things are fixed, a form, that does not know a table of columns, a paging function, inquiry, reset button

integrinI can first build the element in the first step. If you have n, we use one to take a position, the structure is as follows:

  
* N
* N
The rest
* n On behalf of the next, we need to create
2. What methods we need to implement and those

a. Query

b. Click After the page number
  1. c. Reset
  2. d. Select a row
  3. E. The trigger of the rest
  4. One card, it is very clear, because our check data and pagination in an interface I will talk about the page query, and put it in a function with the ordinary query, so the remaining four methods in Methods

Methods: {searchData (PAGENUM = 0) {// query data, ES6 parameter assignment defaults to zero}, selectrowData (row) {// Select a single line is a function of trigger, in each UI There should be this method in the frame table, we only need to implement it,}, resetsearchform () {// Reset Form parameter}, DOFunction () {// Perform other functions}}
  Ok, let's take a look at the way you need to be external, and why is it to be introduced from the outside  
i. First is a query data Method
Reasons: We need to pass from outside, this is a component of the query list, we are definitely not only for an interface, but try to make him a variety of situations for us

II. Methods to pass to the parent component after selecting a single line

In VUE, the sub-component cannot modify the parent component, most of the authors in the frame package is the author’s own packaged Dispatch and Broadcast, But we are applied to your own project, so we don’t have to be so troublesome. If you want to copy a copy in the UI frame source code, we pass a function to the child component through the parent component, then the child component calls this function callback. The parent component is good, so I want to pass a function

III. Other execution functions

3. We want Vue’s DATA parameters and determine which is in the component, Which is external incoming

a. The data binding of the FROM form (but we are not sure that there are several boxes, so you should leave more)

Yes, this one is Enough, what we have to do is dynamically configured, more from the transmission

a. Input an incupone array, there are several conditional search boxes

B Incorporate the array of columns of Table, with the width of each column, column name

    c. Advanture to other function button column array
  1. d. Inferi Paging parameters
  2. e. Introduced data list number
  3. 4. With these, we will make these things in one by one.
Is still starting with the structure

  
Search btn.name
5. Implement an array structure (123)
a. Form (create one first, Then put it in an array) {Label: "Name" DATANAME: "as a bidirectional data binding, as a binding prop Name "} Now, we can't directly define the form of Model structure in this component. We must be dynamically created. In the component, we only have one to create one. Empty objects are good
b. Table-col

“PROP:” Width “Width” Width : “Single List Width”} c. Button

{Name: “Events and Button Name”, TYPE : “Button Type”}
  
6. Next we go to achieve the method we have to introduce

// returns function, You can get SEARCHCHCBFN (RowData) {console.log (rowdata)}}}}}}}}}}}, // Query function, paginum = 0) {API ({Formdata: Formdata, PageData: Pagenum}). Then Res => {console.log (res. Data) this.searchDataList = res. Data.DataList // Page Distribution Size Control this.searchpaging = {… PAGINFO, PAGESIZE: 5}}). Catch (Err => {Throw Err;}}

7. Finally, we will make up all incoming parameters
   
searchDataList: {} searchPaging: {}

concluded
 this is my first time writing to ask to share, it should also be lacking Write logic, if you don't understand, or suggest it, please tell me, code I put in: https://github.com/wqliusong/happy has components, there is a single page that can be running   What I have encountered, one is that Vue's two-way data binding is dynamic, remind everyone, the name is added after the number of times [], can not be used, pay attention to my INPUT, I understand,The parameters in DATA can also be created dynamically. We can solve many problems, so we don't have to care about his initial data format 
Next, I will write a multi-line edited component, although a lot There are also in the UI, but the function is slightly single. Maybe our programmer will solve all the mathematical problems, I have to try to make him a bit of function, in one is about dynamics Increase some implementation of the verification conditions, I hope everyone can have a little harvest

, which is the detailed consolidation of the Vue package function component introduced to you, I hope that if you have any questions, please give me a question. Message, the small package will reply to everyone in time. Thank you very much for your support of Tumi Cloud Website!

© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment