vue $refs的基本用法
来源:互联网 发布:json汉字 编辑:程序博客网 时间:2024/06/05 17:01
<div id="app"> <input type="text" ref="input1"/> <button @click="add">添加</button></div>
<script> new Vue({ el: "#app", methods:{ add:function(){ this.$refs.input1.value ="22"; //this.$refs.input1 减少获取dom节点的消耗 } } })</script>
一般来讲,获取DOM元素,需document.querySelector(”.input1”)获取这个dom节点,然后在获取input1的值。
但是用ref绑定之后,我们就不需要在获取dom节点了,直接在上面的input上绑定input1,然后$refs里面调用就行。
然后在javascript里面这样调用:this.$refs.input1 这样就可以减少获取dom节点的消耗了
阅读全文
1 0
- Vue $refs的基本用法
- Vue $refs的基本用法
- vue $refs的基本用法
- vue $refs的基本用法
- vue-ref-$refs用法
- vue中refs具体用法
- Vue的基本用法
- vue组件($children,$refs,$parent)的使用
- vue组件($children,$refs,$parent)的使用
- Vue之ref与refs的使用
- vue基本使用--refs获取组件或元素
- Vue.js之$refs
- Vue基本用法
- vue 过滤器基本用法
- Vue $emit $refs子父组件间方法的调用
- Vue的基本使用
- vue的基本使用
- vue中常用知识点基本用法
- Xmind基础教程-图标
- 10.管道、脚本支持
- vue之npm与nodejs版本号不一致-spawn cmd ENOENT
- Oracle学习笔记之一
- python环境 sklearn
- vue $refs的基本用法
- Python Qt5 Creator 使用创建项目教程
- Solve It UVA
- 机器学习---GBDT、xgboost与Light GBM优缺点比较(1)
- View视图绘制的过程原理
- xcode代码块的本地路径(以及github下载地址)
- Spring 如何给static变量赋值
- 优化篇 02. 允许远程桌面连接 ❀ Windows Server 2016
- C++语音识别接口快速入门(Microsoft Speech SDK)