查看“︁JavaScript/vue.js/computed”︁的源代码
来自康健生活
←
JavaScript/vue.js/computed
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
== 标题文本 == == 参数透传 == 三层嵌套组件,祖父组件向孙子组件传递 v-model 时可以借助 computed 进行参数透传。 祖父组件 <syntaxhighlight lang="html5"> <template> <ApiModal v-model="visible" /> </template> <script setup> import { ref } from 'vue' const visible = ref(true) </script> </syntaxhighlight> 父组件进行参数透传,或者说某种程度上的参数代理。 <syntaxhighlight lang="html5"> <template> <Modal v-model="visible" /> </template> <script setup> import { computed, defineEmits, defineProps } from 'vue' const emit = defineEmits(['update:modelValue']) const props = defineProps({ modelValue: Boolean, }) const visible = computed({ get: () => props.modelValue, set: (value) => emit('update:modelValue', value), }) </script> </syntaxhighlight> 孙子组件 <syntaxhighlight lang="html5"> <template></template> <script setup> import { defineProps } from 'vue' const props = defineProps({ modelValue: Boolean, }) </script> </syntaxhighlight>
返回
JavaScript/vue.js/computed
。
导航菜单
康健生活
搜索
user-page
通知
user-interface-preferences
个人工具
登录
五一
多读书,多运动,多到远处走走,再看看不一样的世界。