在组件中使用emit需要先进行定义,不然控制台会报警告信息,Vue对子组件调用父组件时的一种约束
app.component("Counter", {
props: ["count"],
emits: ["add"],
methods: {
add() {
this.$emit("add");
}
},
template: `
{{ count }} <button @click="add">++</button>
`
});
生命周期的变化
- 由beforeCreate、created、beforeMount、mounted、beforeUpdate、updated、beforedestroy、destroyed
- 变成了beforeCreate、created、beforeMount、mounted、beforeUpdate、updated、beforeUnmount、unmounted