vue3 —— setup 的执行时机 与 参数(Vue3 — execution timing and parameters of setup)

setup 的两个注意点:

 – setup 执行的时机:

   – 在 beforeCreate 之前执行一次, this是 undefined

 – setup 的参数

   – props:值为对象,包含:组件外部传递过来,且组件内部生命接收了的属性

   – context:上下文对象

     – attrs:值为对象,包含:组件外部传递过来,但没有在 props 配置中声明的属性,相当于 this.$attrs

     – slots:收到的插槽内容,相当于 this.$slots

     – emit:分发自定义事件的函数,相当于 this.$emit

————————

< strong > two points for attention in setup: < / strong >

– timing of setup execution:

– execute once before beforecreate. This is undefined

– parameters of setup

– props: the value is an object, including: the attributes passed from the outside of the component and received by the internal life of the component

– Context: context object

– attrs: the value is an object, including: attributes passed from outside the component but not declared in the props configuration, which is equivalent to this$ attrs

– slots: slot contents received, equivalent to this$ slots

– emit: a function that distributes custom events, equivalent to this$ emit