The setup function

  • Props refers to the value passed by the parent component
  • Context refers to the context (trigger event emit, slot slots and attrs)

Note :(you can’t use es6 deconstruction for props because it makes the props unresponsive. If you want to use deconstruction, you should use toRefs in the Composition API to do the deconstruction.)

 // This is the parent component
 <LoginForm v-model="test" :title="test" />
 
 / / child component
    export default defineComponent({
        name:'LoinForm'.props: {modelValue: {type:number,
            required: true
        },
        title: {type:number,
            default:100}},setup(props, content) {
      console.log('-- -- -- -- -- -- -- -- -- -- -- -- -- -- --')
      let propss = toRefs(props)
      console.log(props.modelValue)
      console.log(propss)
      console.log(content)
     }
    })
Copy the code