首页 > 其他分享 >vue2 ref17 $refs 操控dom

vue2 ref17 $refs 操控dom

时间:2022-11-29 17:26:09浏览次数:49  
标签:cont ref17 dom refs log vue2 console methods

在vue中不建议安装jquery

在vue中操控dom可以用ref方法

 每一个ref对象中都包含一个$refs对象,组件的$refs对象都指向一个空对象

<button @click="clg" class="red">打印</button>
methods: {     clg(){       console.log(this);     },   },

  

 

 

 ref操控dom

<h1 ref="my">111</h1>
clg(){       console.log(this);       console.log(this.$refs.my);       this.$refs.my.style.color = 'red'     },     案例: 子: <p ref="reset">值:{{cont}}</p> <button @click="jia">+1</button>   data() {     return {       cont:0,     }   },   methods: {     jia(){       this.cont += 1     },   },   父: <hello ref="com" @fromCount="getCount"></hello>  <button @click="reset">重置</button>   import hello from '@/components/HelloWorld.vue'   methods: {     reset(){       this.$refs.com.cont = 0     },   },       按需填写案例:     <input type="text" placeholder="999感冒灵" v-if="inputVi" @blur="showinpu" autofocus>     <button v-else @click="inpu">展示</button>   data() {     return {       inputVi: false,     }   },   methods: {     inpu() {       this.inputVi = true     },     showinpu() {       this.inputVi = false     },   },    

标签:cont,ref17,dom,refs,log,vue2,console,methods
From: https://www.cnblogs.com/wencaiguagua/p/16935545.html

相关文章

  • vue2生命周期
    1.有哪些生命周期:beforeCreatecreatedbeforeMountmountedbeforeUpdateupdatedbeforeDestroydestroyed2.一旦进入页面或组件会执行哪些生命周期:beforeCreatecrea......
  • gitee推送更新失败问题记录:remote: error: hook declined to update refs/heads/maste
    问题描述:gitee推送更新时,提示:remote:PoweredbyGITEE.COM[GNK-6.4]remote:error:GE007:Yourpushwouldpublishaprivateemailaddress.    remote:......
  • axios拦截code码,错误处理。vue2版本
    直接上代码importaxiosfrom'axios'import{Notification}from'element-ui';constrequest=axios.create({timeout:10000})//response拦截器获取后......
  • nodejs版本升级到18后,无法启动和打包vue2项目
    引言最近在升级nodejs版本到v18.7.0后启动项目报digitalenveloperoutines::unsupported,经过多方查找最终找到解决方法,特写下此篇原因node.js的版本问题因为node.js......
  • 搞懂vue3的ref、reactive、toRef、toRefs
    首先需要明确这四个函数都是用于在setup中创造响应式变量的。四个函数都需要从vue中导出:import{ref,reactive,toRef,toRefs}from'vue'总结:reactive对比ref从......
  • vue3响应式原理以及ref和reactive区别还有vue2/3生命周期的对比,第二天
    前言:前天我们学了ref和reactive,提到了响应式数据和Proxy,那我们今天就来了解一下,vue3的响应式在了解之前,先复习一下之前vue2的响应式原理vue2的响应式:原理:对......
  • Vue2(笔记02) - Vue核心 - 初识Vue
    初识Vue先引入Vue.js;<scriptsrc="./res/vue.js"></script>vue.js 是开发版的vue.js 会有报错提示,比较友好;生产环境中使用vue.min.js准备好一个容器:<divid="root">......
  • vue3相较于vue2的改动
    v-if和v-for的优先级在vue2中:当v-if和v-for同时使用时,v-for的优先级高于v-if(因此我们通常需要计算属性先对数据进行加工处理,以达到性能优化的目的)在vue3中:当v-if和v-for......
  • Vue2(笔记01) - 基础 - Vue简介
    笔记来自尚硅谷课程:1Vue是什么?一套用于构建用户界面的渐进式Javascript框架;它基于标准HTML、CSS和JavaScript构建,并提供了一套声明式的、组件化的编程模型,帮助你高效......
  • vue2 组件共享数据 父子组件 兄弟组件
    父子组件:父只管定义数据和传数据子只管接收数据和声明数据父:<hello:msg="message":user="username"></hello>importhellofrom'@/components/HelloWorld......