vue3中$refs使用调整

前言: vue3环境

在vue2环境中,可以直接通过this.$refs获取模块;在vue3环境中,通用以下两种方式获取:

1、通过声明ref进行获取;

TypeScript 复制代码
import { ref} from 'vue';
const logoForm = ref();
console.log(logoForm.value);

2、通过声明getCurrentInstance进行获取;

TypeScript 复制代码
import { getCurrentInstance } from '@vue/runtime-core';
const currentInstance = getCurrentInstance();
console.log(currentInstance.ctx.$refs.logoForm);
相关推荐
2013编程爱好者4 小时前
Vue工程结构分析
前端·javascript·vue.js·typescript·前端框架
小满zs5 小时前
Next.js第十一章(渲染基础概念)
前端
不羁的fang少年6 小时前
前端常见问题(vue,css,html,js等)
前端·javascript·css
change_fate6 小时前
el-menu折叠后文字下移
前端·javascript·vue.js
yivifu6 小时前
CSS Grid 布局详解(2025最新标准)
前端·css
o***Z4488 小时前
前端性能优化案例
前端
张拭心8 小时前
前端没有实际的必要了?结合今年工作内容,谈谈我的看法
前端·ai编程
姜太小白8 小时前
【前端】CSS媒体查询响应式设计详解:@media (max-width: 600px) {……}
前端·css·媒体
weixin_411191848 小时前
flutter中WebView的使用及JavaScript桥接的问题记录
javascript·flutter
HIT_Weston8 小时前
39、【Ubuntu】【远程开发】拉出内网 Web 服务:构建静态网页(二)
linux·前端·ubuntu