- 它比
beforeCreate
和created
这两个生命周期还要快,就是说,setup在beforeCreate,created
前,它里面的this打印出来是undefined
- setup可以接受两个参数,第一个参数是
props
,也就是组件传值,第二个参数是context
,上下文对象,context
里面还有三个很重要的东西attrs
,slots
,emit
,它们就相当于vue2里面的this.$attrs
,this.$slots
,this.$emit
。