【发布时间】:2018-08-08 13:21:19
【问题描述】:
我有 2 个路由器链接链接到同一页面(定义页面)但具有不同的 id,在我的定义页面中我有一个 if else 循环检查 id 然后发布该 id 的适当定义。我的问题是我的循环无法正确读取我的 id 并直接进入我的 else 语句,这是我让它工作的最接近的。
第 1 页中我的 2 个路由器链接
<router-link :to="{ path: '/Pulse/Definition',id:'Alignment'}" v-bind:tooltip="Alignment" append><a >Read more ></a></router-link>
<router-link :to="{ path: '/Pulse/Definition'}" id="Trust" append><a >Read more ></a></router-link>
我的定义页面
<template>
<div class="PulseDefinition page row">
<h2 v-if=" id=='Alignment'">hello world {{id}}</h2>
<h2 v-else-if=" id=='Trust'">hello world {{id}}</h2>
<h2 v-else>Sorry try again</h2>
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
.PulseDefinition{
margin-top:2.5rem;
margin-left:3rem;
background-color: aquamarine;
width:50rem;
height:50rem;
}
</style>
路由器
import Vue from 'vue';
import Router from 'vue-router';
import Community from '../components/PulseCommunity';
import Home from '../components/Home';
import Definition from '../components/Definition.vue';
Vue.use(Router)
export default new Router({
routes:[
{
path:'Tuba',
name:'Tuba',
component: Default
},
{
path:'/Pulse',
name:'Pulse',
component:PulseNav,
children:[{
path:'/Pulse/Overview',
name:'Overview',
component:Overview
},
{
path:'/Pulse/Personal',
name:'Personal',
component:Personal
},
{
path:'/Pulse/Community',
name:'Community',
component:Community
},
{
path:'/Pulse/Definition/:id',
name:'Pulse Definition',
component:Definition
}
]
},
{
path:'/Coaching',
name:'Coaching',
component:Coaching
},
{
path:'/Comunication',
name:'Comunication',
component:Comunication
},
{
path:'/Home',
name:'Home',
component:Home
},
]
})
【问题讨论】:
-
我忘了提到,由于我的尝试,我的两个路由器链接略有不同,我把它们留在那里,希望其中至少有一个是正确的做法
-
我的依赖项显示我有 "vue": "^2.5.16", "vue-router": "^3.0.1"
-
我的回答好运吗?
-
还没有,我在让 const 路由器在我的脚本标签中工作时遇到了一些麻烦,所以我改用了这个"
标签: vuejs2 routerlink