1. Passing values from parent component to child component
The translation is as follows: Avoid making modifications to the prop directly, as the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the value of that prop.
That is to say, you cannot modify the received value directly in the component, because this will cause problems in the use of other components. You should change its own data or properties in this component. How to write it? code show as below:
props: ['count'], data () { return { number: this.count //Give the value of count to your own number } }, template: `<div @click="handleCountClick">{{number}}</div>`, methods: { handleCountClick() { this.number ++; } }
2. Pass values from the component to the parent component
this
.
$emit
(
'change'
,
1
) 1 is the parameter to carry
handleChange
(
aaa
) {//aaa accepts the carried parameters
this
.
total
+=
aaa
;
}