dynamic way to use ref to bind children component,and call children method when build
Vue version
3.2.37
Link to minimal reproduction
Steps to reproduce
just click the number text,the consolog is error
What is expected?
in dev mode
the cRef should be a object
in pro mode
can call exMethod
method successful
What is actually happening?
in dev mode
the cRef is a array
. I have to check if it is array,and pick the first element to be the true ref refrence.in this way the dev mode can call method named exMethod
successful
in pro mode
console.log show that Cannot read properties of undefined (reading 'exMethod')
System Info
System:
OS: Windows 10 10.0.19044
CPU: (4) x64 Intel(R) Core(TM)2 Duo CPU T7700 @ 2.40GHz
Memory: 6.43 GB / 16.00 GB
Binaries:
Node: 16.15.0 - D:\node\node.EXE
Yarn: 1.22.18 - ~\AppData\Roaming\npm\yarn.CMD
npm: 8.5.5 - D:\node\npm.CMD
Browsers:
Edge: Spartan (44.19041.1266.0), Chromium (103.0.1264.71)
Internet Explorer: 11.0.19041.1566
npmPackages:
vue: ^3.2.36 => 3.2.37
Any additional comments?
No response
The use of the way you don't
Ref support array api but do not support the api of objects
you can see the document -> api document
I implemented a demo , you can see the demo
extension
Consider support object api for template-refs ?
@cuixiaorui
it must be
const getComponentByName = (name)=> itemRefs.value.find((c)=> c.name === name)