suppose you have the following example:
1, parent component
<template>
<test1 :handleChange="onChange" />
<test2 @handleChange="onChange" />
</template>
<script>
...
methods: {
onChange(data) {...}
}
...
</script>
2, test1 components
<template>
<div @click="onChange"></div>
</template>
<script>
...
props: {
handleChange: Function
},
methods: {
onChange() {
this.handleChange(123)
}
}
...
</script>
3, test2 components
<template>
<div @click="onChange"></div>
</template>
<script>
...
methods: {
onChange() {
this.$emit("handleChange", 123)
}
}
...
</script>
question:
both the test1 component and the test2 component delegate events externally, but one is in the form of property methods used, and the other is in the form of delegated events. When the parent component makes the call, it finds that both of them can do the same thing.
what is the difference between them?
the difference I know so far is:
1. Using the form of attributes is equivalent to passing external methods to subcomponents to make calls, while delegating events is the way in which subcomponents report an event to the outside and receive and execute it from the outside.