当前位置:网站首页>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


边栏推荐
- In navigation, the solution of adding borders to affect the layout
- itk::SymmetricForcesDemonsRegistrationFilter
- Rust language learning
- Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference
- [译] Go语言测试进阶版建议与技巧
- Difference between Definition and Declaration
- ITK 多阶段配准
- Bat interview & advanced, get interview materials at the end of the text
- 点云配准--gicp原理与其在pcl中的使用
- Numpy numerical calculation basis
猜你喜欢

Time series database - incluxdb2 docker installation

JS how to convert a string into an array object

VGG小卷积代替大卷积 VS 深度可分离卷积

Deep analysis of advanced pointer -- advanced chapter of C language

Advanced chapter of C language -- ten thousand words explanation pointer and qsort function

时序数据库 - InfluxDB2 docker 安装

Rust语言学习

MySQL review

安装canvas遇到的问题和运行项目遇到的报错

JS string array converted to numeric array and how to add the numbers in the array
随机推荐
Advanced C language -- storage of floating point in memory
In navigation, the solution of adding borders to affect the layout
Differences between server-side rendering and client-side rendering (advantages and disadvantages)
This direction of ordinary function and arrow function
Micro task, macro task and event loop of JS
stress - 系统压力模拟工具
Macro compilation preprocessing header Win32_ LEAN_ AND_ MEAN
Principle of master-slave replication of redis
爱可可AI前沿推介(6.12)
NDT配准原理
回溯法, 八皇后
[转]placement new
鸡尾酒排序
Dom+js+ carousel map + no time
AutoLock 解决加锁后忘记解锁问题
What is modularity? Benefits of modularity
Numpy numerical calculation basis
Vs2019 set ctrl+/ as shortcut key for annotation and uncomment
From simple to deep - websocket
从小白入手,从已经训练好的模型中取出weight权重参数绘制柱状图