Vue3访问不到$refs?

我试过了,getCurrentInstance()的方法

我试过

js 复制代码
// 伪代码
<tinymce :ref="tinymceDate" />

setup(){
let tinymceDate  = ref(null)
const publish = () => {
      console.log("hfq",tinymceDate.value)
    }
return{...}
}

都不行

后面我试着在setup中使用setup(prop, context) 使用context.$refs这样去访问.因为在我的理解中setup传值中的context就等于this

事实证明我还是对前端的理解不够, context中没有$refs这个东西

随后我放弃了在setup中设置方法,我直接在method中定义方法,成功访问到$refs

js 复制代码
methods:{
    publish(){
      console.log(this.$refs.tinymce)
    }
  },

自己的前端知识还是掌握的不够扎实

相关推荐
Irene199114 分钟前
Vue 3 中移除了 $on、$off 和 $once 方法(附:Composables 组合式函数 使用详解)
vue3
Sapphire~1 天前
Vue3-15 html标签和组件上的ref属性 + 接口泛型
vue3
Irene19911 天前
Vue 3 中使用 Mitt 事件总线
vue3·mitt
咸甜适中1 天前
双色球、大乐透兑奖分析小程序(rust_Tauri + Vue3 + sqlite)
爬虫·rust·sqlite·vue3·tauri2
Sapphire~3 天前
Vue3-012 vue2与vue3中的computed
vue3
Sapphire~6 天前
Vue3-11 toRefs 和 toRef
vue3
华玥作者7 天前
uni-app + Vite 项目中使用 @uni-helper/vite-plugin-uni-pages 实现自动路由配置(超详细)
前端·uni-app·vue·vue3·vite
独立开发者阿乐8 天前
Vue3中Markdown解析与渲染的完整解决方案:从安全到性能优化
web安全·性能优化·vue3·前端开发·语法高亮·markdown解析·markdown-it
Sapphire~9 天前
Vue3-10 ref与reactive创建响应式数据的区别
vue3
Irene199110 天前
Vue3 TypeScript 项目中,Emits 验证的使用场景
typescript·vue3·验证