2024年06月14日 建站教程
vue开发中,如何获取父组件传递的值?下面web建站小编给大家简单介绍一下具体实现代码!
具体代码如下:
<template>
<h2>子组件</h2>
<div @click="sonHander">
我是子组件中的数据
</div>
<h2>使用了props声明接收==>{{ mytitle }}</h2>
<h2>使用参数attrs获取==>{{ attrs.othertitle }}</h2>
</template>
<script>
import { defineComponent,setup } from "vue";
export default defineComponent({
name: "NoCont",
props:{
mytitle:{
type:Object
}
},
setup(props,{attrs,slots,emit}){
function sonHander(){
emit("sonclick","子组件传递给父组件")
}
return {sonHander,attrs}
}
});
</script>
本文链接:http://so.lmcjl.com/news/6521/