vue3 - setup之defineEmits

基础形式

子组件

const emits = defineEmits(['name'])

//触发emits事件
const eventButton = () => {
 emits('name')
}

父组件

<script>
const handleName = () =>{
}
script>
<template>
  <ComponentName @name="handleName" />
template>

传值

子组件

const emits = defineEmits(['name'])

//触发emits事件
const eventButton = () => {
 emits('name',{child1:1,child2:2})
}

父组件

<script>
const handleName = (num) =>{
  console.log(num.child1)
  console.log(num.child2)
}
script>
<template>
  <ComponentName @name="handleName" />
template>

你可能感兴趣的:(#,Vue3,vue,#,nextjs,vue.js,前端,javascript)