vue3接收props
时间: 2023-09-12 22:13:16 浏览: 92
在Vue3中,可以通过在`setup`函数的参数中声明`props`来接收父组件传入的属性值。如果没有使用`<script setup>`的组件,可以使用`props`选项来声明属性。例如:
```
export default {
props: ['foo'],
setup(props) {
console.log(props.foo)
}
}
```
在`setup`函数中,可以通过`props`参数获取到父组件传入的属性值,并进行相应的操作。如果`vnode`中存在`props`,则会将`props`挂载到`instance`下的`props`字段中。这样就可以在组件中使用接收到的`props`了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Vue3中props的原理与使用](https://blog.csdn.net/qq_17189095/article/details/131811584)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* [Vue3 - props](https://blog.csdn.net/B1841630/article/details/129362131)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文