Vue.js 此.$refs,此.$router,此.$route access与Vue 2组合API

Vue.js 此.$refs,此.$router,此.$route access与Vue 2组合API,vue.js,vuejs2,vue-component,vue-router,vue-composition-api,Vue.js,Vuejs2,Vue Component,Vue Router,Vue Composition Api,您能告诉我如何访问Vue 2 Composition API设置函数中的this.$refs,this.$router,this.$route?context中提到了一些解决方案。$root但是$root在context中不再可用。请帮忙 我正在使用VUE2和CompositionAPI插件。似乎useRoute或useRouters不支持Vue 2路由器版本用户路由和用户路由。您可以从其模块导入路由器,并从中访问路由器和路由 参照的使用方法与Vue 3中的相同: import{ref,onMo

您能告诉我如何访问Vue 2 Composition API设置函数中的
this.$refs
this.$router
this.$route
context中提到了一些解决方案。$root
但是
$root
context
中不再可用。请帮忙


我正在使用VUE2和CompositionAPI插件。似乎
useRoute
useRouters
不支持Vue 2路由器版本用户路由和
用户路由

您可以从其模块导入路由器,并从中访问
路由器
路由

参照的使用方法与Vue 3中的相同:

import{ref,onMounted}来自“@vue/compositionapi”//导入参考,未安装
从“@/router”//导入路由器导入路由器
导出默认值{
设置(){
console.log(路由器);//这个。$router
console.log(router.app.route);//this.route
常量myref=ref(null);//创建ref
未安装(()=>{
console.log(myref);//this.$refs.myref
});
return{myref};//返回模板ref
},
};

非常感谢。这起作用了:)