VUE parent subcomponent data delivery example

  
   

Template AAA => {{msg1}}
// MSG1 Write here is oxygen, because this is This method is not possible in the parent component internal //
// This way is not possible, this is inside the sub-component, where to display the number of parent components here //, need to define attributes with the PROPS
  VAR VM = New Vue ({EL: "# box", DATA () {a: 'aaa'}, Components: {'aaa': {data () {msg1: 'parent component data'}, template: '# aaa', components: {'bbb': {// Props: [ 'm'], // This is a way of writing, which defines attributes: {'m': string // this is the second way of writing, object form: Template: '

This is Submail BBB - {{M}}

'}}}}}}}}}}}})
From this example, the parent component is transmitted to the sub parts. Data, because every component is independentIn the field, the data of the parent component is displayed in the sub-component. To use the PROPS defined attribute to bind the data in the parent component, if the data of the parent component here is MSG1, define an attribute M with PROPS to receive Data MSG1; Display parent components in the form of {{m}} in the form of subcomponents

parent components can not only deliver data to the sub parts, but also methods, such as:

  This is a sub-assembly, referenced in the parent component, where: Get -DataS = "getcreateissues" receives a method, this method is passed to subcaps from the background in the parent component, and these data can be displayed in subcomponents,    
Methods: {GetCreateissues () {// This is the format of ES6 this. $ Http.get (URL, DATA) .Then (res => {}) // This is also ES6 format}}

   Code 
code is as follows:

PROPS: [‘ExecutorsData’, ‘Isshow’, ‘MODELTYPE’, ‘IssueData’, ‘User’, ‘Projects’, ‘Title’, ‘GetData’, ‘Getitdata’, ‘LocalToken’, “UserName”, “TokenData”],

GetData is a method of receiving data from the parent component, corresponding to: get-DataS = “getcreateissues, in subcomponents can directly use GetDataS, such as:


Methods: {ookconfirm () {IssueApi.delissue (this.delid) .Then (res. => {== 0) {this.successpop ‘Delete Success’; this.openconfirm = false; this.isshow = false; // This is the method of using the parent component this.getData (); // end this. $ Dispatch (‘fetchlist’);} else { “}}}}}}}}}}}}}}}}}

2. Subcuffs pass data to parent components

  After selecting conditions in subassembly, performing search function in parent components  

Clear

Search

// ModalData is a data that needs to be sent to the background vue父子组件的数据传递示例

  
Export Default {Props: ['confirm'], data () {return {modaldata: {projvername: '' '}}}}

Defines a CONFIRM method to receive the method in the parent component, where data is transmitted from the sub-component to the parent component is not using $ EMIT, but directly transmits the data as a parameter to the method, in the father Such use in the component:
   
Data () {RETURN {SearchData: {projvername: ”,}}}, methods: {search (data) {// DATA is the value of the data passed by the subcomponent passing this.SearchData.ProjverName = data.projvername; THIS. $ http.get (url, this.searchdata.projvername) .Then (res => {console.log (res)}}

This method It is to pass data from subcompons to parent components,
   From sub-components to parent components, it is necessary to use $ dispatch, such as:   
After you click Save, this pop-up box disappears, and the latest data needs to be obtained in the parent component. This is required to send this save event to let the parent component know, usage:
  Copy code  The code is as follows: 
Save


vue父子组件的数据传递示例 Methods: {save () {this. $ http.post (url, data) .then (RES=> {Console.log (‘Susing Success’); this. $ route.router.go ({name:’ issues.issuelist ‘}); // Save After jump to the corresponding routing this. $ dispatch (‘ Dissave ‘) // Here the save event is sent out})}}

Use Events in the parent component to receive this event, and perform some actions, such as:

Events: {DISSAVE () {// This is the method of the received subcomponents this.getCreateiss (); // After receiving a method to get a short data, so After you click Save in the subcomponents, the parent component can directly get the latest data}}}}}}}}}}}}}}, The tutorial can be used to pass data to the parent components. Method, use $ EMIT

The above is all of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment