美文网首页
vue3 -script-setup emits - defin

vue3 -script-setup emits - defin

作者: 小李不小 | 来源:发表于2021-07-13 09:21 被阅读0次

子组件

<template>
  <h1>{{ msg }}</h1>
  <button @click="inc">点击新增</button>
</template>

<script setup>
//  $emits使用 defineEmits 来代替了
  import {defineEmits} from 'vue'

  const emits = defineEmits(["onSubmit", "onExport"]);
   const inc=()=>{
       emits("onExport",'emits----');
  }

    

</script>

父组件

<template>
  <img alt="Vue logo" src="./assets/logo.png" />
  <HelloWorld @onExport="clickadd"  msg="Hello Vue 3.0 + Vite  传过来的" />
</template>

<script setup>
//值计入引入就可以了
import HelloWorld from './components/HelloWorld.vue'

const clickadd=(e)=>{
  console.log('index---addd',e)
}
</script>
父组件接收到子组件的事件响应
image.png

相关文章

网友评论

      本文标题:vue3 -script-setup emits - defin

      本文链接:https://www.haomeiwen.com/subject/vsifpltx.html