当前位置:网站首页>this.$ How to solve the problem when refs is undefined?
this.$ How to solve the problem when refs is undefined?
2022-06-12 12:33:00 【Fashion_ Barry】
First, you should know this.$refs What is it ?
ref There are three uses :
1、ref Add to common elements , use this.$refs.name What you get is dom Elements
2、ref Add to the subcomponent , use this.$refs.name Get the component instance , You can use all the methods of the component
3、 utilize v-for and ref You can get a set of arrays or dom node
When v-for For elements or components , The reference will contain DOM An array of node or component instances .
ref Itself is created as a result of rendering , You can't access them during the initial rendering --- Because they don't exist yet ;$refs It's not reactive either , So you can't try to use it for data binding in a template
What you get is always undefined Of
1、 Where did you call it , And the object you call
Try at mounted() Is there any effect of calling inside ;
The called object itself exists , It still needs data rendering ; In the same way mounted() It calls , Or in this.$nextTick( () => { ... } ) call
2、 Whether the called object is the same as v-for Use a combination of , Or whether the calling object is an array list
If I set it now ref stay v-for On , Direct access to this.$refs.name.style, It's always empty ;
because this.$refs.name Is an array , Unable to get .style obtain ;
You can dynamically bind ref And use v-for, Use this.$refs[refName][index] obtain ;
3、 Whether the called object is the same as v-if Use a combination of
ref Not reactive , All dynamically loaded templates cannot be updated accordingly ;
solve : Replace with v-show that will do


边栏推荐
- 关系代数笛卡尔积和自然连接的例子
- Imx6 uboot add lvds1 display
- MVC mode, encryption, jsonwebtoken
- Deep analysis of advanced pointer -- advanced chapter of C language
- You can't just use console Log ()?
- Start with Xiaobai, take the weight parameter from the trained model and draw the histogram
- Boot entry directory
- AGCO AI frontier promotion (6.12)
- ACE配置IPv6, VS静态编译ACE库
- AND THE BIT GOES DOWN: REVISITING THE QUANTIZATION OF NEURAL NETWORKS
猜你喜欢

VS2019 设置 CTRL+/ 为注释和取消注释快捷键

C语言进阶篇——万字详解指针和qsort函数

JS convert string to array object

C语言进阶篇——浮点型在内存中的存储
![[JS] some handwriting functions: deep copy, bind, debounce, etc](/img/f8/cf51a24450a88abb9e68c78e0e3aa8.jpg)
[JS] some handwriting functions: deep copy, bind, debounce, etc

Point cloud registration -- GICP principle and its application in PCL

BAT面试&高级进阶,文末领取面试资料

In navigation, the solution of adding borders to affect the layout

In depth anatomy of C language - key words & supplementary contents

Async/await for ES6
随机推荐
[转]placement new
KDD2022 | 边信息增强图Transformer
sublime_ Textuse
You can't just use console Log ()?
Examples of Cartesian product and natural connection of relational algebra
InfluxDB2.x 基准测试工具 - influxdb-comparisons
AND THE BIT GOES DOWN: REVISITING THE QUANTIZATION OF NEURAL NETWORKS
22年gdcpc广东省赛记录
ACE配置IPv6, VS静态编译ACE库
【VIM】.vimrc配置,已经安装Vundle,YoucompleteMe
三维坐标点拟合球(matlab and C )
机械臂雅可比矩阵IK
Video speed doubling in PC browser
Various data transmission
Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference
牛顿法解多项式的根
Macro compilation preprocessing header Win32_ LEAN_ AND_ MEAN
ITK 多阶段配准
JS attribute operation and node operation
Autolock solves the problem of forgetting to unlock after locking