IT이야기

vue js에서 특정 구성 요소로 리디렉션하는 방법

cyworld 2022. 4. 1. 21:06
반응형

vue js에서 특정 구성 요소로 리디렉션하는 방법

아래와 같이 라우터 링크를 사용하지 않고 페이지 새로 고침 없이 URL 내에서 리디렉션하고 싶다.

<router-link to="/about us " active-class="active">foo</router-link>

다음과 같은 경로를 인쇄하고 싶다.

<li class="nav-item phone">
    <a class="nav-link" href="contact-us.html">
        اتصل بنا
    </a>
</li>

내 경로:

const routes = [
    { path: '/aboutus/', component: AboutUs }
]

이것을 사용해 보십시오.

this.$router.push('about')

너는 이것에 대한 해결책이 필요할지도 모른다.

이 솔루션으로는url어느 쪽이든 :)

설정하다html자료에 의하면

    data: () => {
        return {
            html: null
        }
    }

당신의 컨텐츠를 얻으십시오.html모든 요청을 사용하여 파일링하고 에 할당htmldata단면도어떤 라이프사이클 훅에서도 이것을 가져갈 수 있다.여기 내가 사용하고 있다.beforeMount.

    beforeMount() {
        this.fetchAllEmployees();
        axios.get('contact-us.html')
            .then(response => {
                this.html = response.data;
            })
    }

이제 너는 그 모습을 보여줄 수 있다.html이와 같은 구성 요소의 내용

<template>
    <div>
        <div v-html="html"></div>
    </div>
</template>

를 클릭할 때만 표시하려면a태그, 에서 다른 변수를 추가할 수 있음data값을 전환하기 위해 사용할 수 있다.

참조URL: https://stackoverflow.com/questions/60937965/how-to-redirect-to-specific-component-in-vue-js

반응형