Gets to get the values ​​in the props in the Methods of the PROPS.

Father subcomponent communication

This official website is very clear, it is also very simple, the parent component is used in the parent component, and the subcomponents can be received using the PROPS

, For example:

   
Data statistics
Sales number
{Number}}
Sales amount
{{Amount} Profit statistics
{PROFITS}
DATA () {Return {Number: NULL, AMOUNT: NULL, PROFITS: NULL, CHARTDATA: [10, 10, 10]}}
Export Default {Props: ['ChartData'
In this case, I want to take the value in the props in the Methods of the subcaps, using this.Chartdat.A can be

, in case, the value in your ChartData is not fixed, but dynamically obtained, in which case you will find Method, you can’t get your ChartData. , Or taken the default value

, this case
   

DATA: NULL, AMOUNT: NULL, PROFITS: NULL, CHARTDATA: []}} () () {this.getStatistics ();}, methods: {// Get the statistics getStatistics () {console.log (‘Get Statistics’) AXIOS.POST (API, {}). Then ((res) => {this.number = res. Data.domain.list [0]. Number; this.amount = res.data.domain.list [0] .amount; this.profits = res. Data.domain.list [0] .profits; this.chartdata = [this.number, this.amount, this. .profits];}). Catch ((ERR) => {Console.log (ERR);})}}}},},

At this time, it is not existed in Methods of Methods at this time (because it is empty)

I used Watch processing

The solution is as follows:
  Using WATCH    
PrOPS: [‘ChartData’], DATA () {Return {CDATA: []}}, watch: {chartdata: function (newval, oldval) {this.cdata = newVal // NewVal is chartdata this.drawchart ();}},
listening to the value of chartdata, triggered when it is turned by empty, at this time, you can get it. After getting the value after the value, the method of performing

in Watch

above the Methods of the Methods of the PROPS is to share all the contents of the small package, I hope to give you a reference, I hope everyone will support Tumi Clouds.

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

Please log in to comment