Home> Web Front-end> Vue.js> body text

How to use vue3 setup syntax sugar

王林
Release: 2023-05-10 11:43:05
forward
1365 people have browsed it

    1. Introduction to setup syntax sugar

    You can use setup syntax sugar directly by adding the setup attribute in the script tag.

    After using setup syntax sugar,there is no need to write a setup function; components only need to be introduced without registration; properties and methods do not need to be returned and can be used directly in the template.

     
    Copy after login

    2. New api in setup syntax sugar

    • defineProps: Child component receives props passed from parent component

    • defineEmits: The child component calls the method in the parent component

    • defineExpose: The child component exposes properties, which can be obtained in the parent component

    2.1defineProps

    Parent component code

     
    Copy after login

    Child component code

     
    Copy after login

    2.2defineEmits

    Subcomponent code

     
    Copy after login

    Parent component code

     
    Copy after login

    2.3defineExpose

    Subcomponent code

     
    Copy after login

    Parent component code

     
    Copy after login

    Supplement: used with ordinary script

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!