markRaw获取子组件参数
时间: 2023-10-13 21:04:32 浏览: 48
您好,感谢您的提问。如果您想获取一个使用Vue的markRaw()函数来标记为原始对象的子组件的参数,可以通过以下方式来实现:
1. 在子组件中使用props将参数传递给子组件。
2. 在父组件中引入子组件,并将参数传递给子组件。
3. 在父组件中使用markRaw()函数将传递给子组件的参数标记为原始对象。
4. 在子组件中使用$props来获取父组件传递的参数,此时可以获取到被标记为原始对象的参数。
以下是一个示例代码:
```
<template>
<div>
<child-component :childProps="rawChildProps"></child-component>
</div>
</template>
<script>
import { markRaw } from 'vue';
import ChildComponent from '@/components/ChildComponent.vue';
export default {
components: {
ChildComponent
},
data() {
return {
parentProps: {
data1: 'hello',
data2: 'world'
}
}
},
computed: {
rawChildProps() {
return markRaw(this.parentProps);
}
}
}
</script>
```
在子组件中,可以通过`$props.childProps`来获取父组件传递的`parentProps`参数,并且此时可以获取到被标记为原始对象的参数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)