세 개의 파일이 router.js
있으며 다음 App.vue
과 Contents.vue
같습니다.
router.js
:
{
path: '/views/frames/viewContentId1',
name: 'letsCheck1',
component: () => import('./views/frames/Contents.vue'),
props: {
id: '1'
}
},
{
path: '/views/frames/viewContentId2',
name: 'letsCheck2',
component: () => import('./views/frames/Contents.vue'),
props: {
id: '2'
}
},
App.vue
:
<div class=" Button to display content of Id1">
<vs-button @click="$router.push({name: 'letsCheck1'}).catch(err => {})">Explore Light</vs-button>
</div>
<div class=" Button to display content of Id2">
<vs-button @click="$router.push({name: 'letsCheck2'}).catch(err => {})">Explore Deep</vs-button>
</div>
Contents.vue
:
<div class="Whole contents are present here">
<p> Here this content is same for both the id</p>
<span v-if="id === '1' ">Top Notch1</span>
<span v-if="id === '2' ">Top Notch2</span>
<p> Here again this content is same for both the id</p>
</div>
<script>
props: {
id: String,
required: true
}
</script>
실제로 코드를 router.js
. id
두 번 지정 했지만 id
약간의 변경 사항으로 표시 할 동일한 정보를 더 추가하고 싶다고 가정합니다. 에서 볼 수 있듯이 지시문 Contents.vue
을 사용하여 약간의 변경 사항을 표시했습니다 v-if
.
따라서 경로를 한 번만 정의 할 수있는 방법과 id
버튼에을 지정하는 방법을 알고 싶습니다 id
.
동적 라우팅으로 할 수 있습니다. 설명서를 확인하십시오 .
Router.js
{
path: '/views/frames/:viewContentId',
name: 'letsCheck1',
component: () => import('./views/frames/Contents.vue'),
props: {
id: '1'
}
},
앱보기
<div class=" Button to display content of Id1">
<vs-button @click="$router.push({name: 'letsCheck1',params: { viewContentId: '1' }})">Explore Light</vs-button>
</div>
<div class=" Button to display content of Id2">
<vs-button @click="$router.push({name: 'letsCheck1',params: { viewContentId: '2' }})">Explore Light</vs-button>
</div>
Contents.vue
<div class="Whole contents are present here">
<p> Here this content is same for both the id</p>
<span v-if="$route.params.viewContentId === '1' ">Top Notch1</span>
<span v-if="$route.params.viewContentId === '2' ">Top Notch2</span>
<p> Here again this content is same for both the id</p>
</div>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다