Getting a value from the `props` in root scope of `<script setup>` will cause the value to lose reactivity.
时间: 2023-12-04 17:47:59 浏览: 177
回答: 当在`<script setup>`的根作用域中从`props`中获取值时,会导致该值失去响应性。 这意味着无论父组件传递的数据是否具有响应性,当我们从props中接收数据时,需要将其转换为响应式数据。为了实现这一点,我们可以使用`toRefs(props)`将props对象转换为具有ref的普通对象,从而确保我们可以获取到具有响应性的数据。<em>1</em><em>2</em><em>3</em>
#### 引用[.reference_title]
- *1* [【Vue3】报错处理合集](https://blog.csdn.net/Qxn530/article/details/126856780)[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^v92^chatsearchT0_1"}} ] [.reference_item]
- *2* [undefined](undefined)[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^v92^chatsearchT0_1"}} ] [.reference_item]
- *3* [Getting a value from the `props` in root scope of `setup()` will cause the value to lose reactivity](https://blog.csdn.net/weixin_47300795/article/details/123489366)[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^v92^chatsearchT0_1"}} ] [.reference_item]
[ .reference_list ]
阅读全文