programing

this.$refs, this.$140, 이거요.Vue 2 Composition API를 사용한 $route 액세스

itsource 2022. 8. 1. 22:04
반응형

this.$refs, this.$140, 이거요.Vue 2 Composition API를 사용한 $route 액세스

접속 방법을 알려주시겠습니까?this.$refs,this.$router,this.$routeVue 2 Composition API 셋업 기능에 포함됩니까?에는 다음과 같은 솔루션이 있습니다.context.$root그렇지만$root에서는 사용할 수 없습니다.context더이상.제발 도와주세요.

컴포지션 API 플러그인과 함께 Vue 2를 사용하고 있습니다.그런 것 같다useRoute또는useRouters는 Vue 2 라우터 버전을 지원하지 않습니다. useRoute그리고.useRouters는 Vue-router v4에서 사용할 수 있습니다.

모듈에서 라우터를 Import하여 두 개의 라우터에 모두 액세스 할 수 있습니다.router그리고.route그것으로부터.

참조는 Vue 3과 동일한 방법으로 사용할 수 있습니다.

import { ref, onMounted } from "@vue/composition-api";   // import ref, onMounted
import router from "@/router";                           // import router

export default {
  setup() {
    console.log(router);                                 // this.$router
    console.log(router.app.$route);                      // this.$route

    const myref = ref(null);                             // create ref
    onMounted(() => {
      console.log(myref);                                // this.$refs.myref
    });

    return { myref };                                    // return for template ref
  },
};

언급URL : https://stackoverflow.com/questions/66469544/this-refs-this-router-this-route-access-with-vue-2-composition-api

반응형