The child component reported an error when a parent-child parameter was passed in the request Cannot read properties of undefined #7146
Answered
by
chenxch
Silence-dream
asked this question in
Help/Questions
-
在请求中使用父子传参,子组件报错 The child component reported an error when a parent-child parameter was passed in the request |
Beta Was this translation helpful? Give feedback.
Answered by
chenxch
Nov 16, 2022
Replies: 2 comments 1 reply
-
// bad
{{props.users[0].name}}
// 在template 无需要在写props了,然后在使用数组下标的时候要判断下标是否存在哦
{{users?.[0].name}} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Silence-dream
-
First of all the error is define the ref like this: const data = ref(); the data's value is I think you should use <Comp v-if="users" :users='users'/> or processing the props with {{props.users ? props.users[0].name : ''}} or
or use const name = computed(() => {
return props.users ? props.users[0].name : ''
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
playground