跳到主要内容

useAttrs

2023年10月24日
柏拉文
越努力,越幸运

一、认识


useAttrs$attrs 作用一样, 主要用于子组件获取父组件中没有通过 props 或者 emits 接收的属性和自定义事件。

二、语法


<template>
<Child :a="a" :b="b" :c="c" @handleChange="handleChange" />
</template>

<script setup>
import { ref, onMounted } from 'vue';
import Child from './components/Child.vue';

const a = ref(0);
const b = ref(1);
const c = ref(2);

const handleChange = value => {
console.log(value);
};
</script>