首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >VueJs路由器-链路不工作,但从它复制的链接在另一个选项卡中工作。

VueJs路由器-链路不工作,但从它复制的链接在另一个选项卡中工作。
EN

Stack Overflow用户
提问于 2020-02-04 08:41:07
回答 1查看 80关注 0票数 0

我正在用VueJ构建一个网络应用程序。我有三页,应用程序,注册表,身份。在应用程序页面中,有一个带有link1 (localhost:8080/app/{appid}/regs)的应用程序的表,用于查看每一行的注册表。类似地,在注册表页面中,有一个link2 来查看它的应用程序。

我的问题是,当我单击link1时,它会带我到注册表页面,但当我单击link2时,它会带我到localhost:8080而不是localhost:8080/app/{appid}/regs/{regid}/ids。但是,当我从link2复制地址并粘贴到地址栏时,它会带我到所需的页面。我做错了什么?

而且我在控制台里收到了警告-

警告命名路由“regs”缺少param :预期要定义的"appid“

Vue警告命名路由“ids”缺少param :需要定义的"appid“

router.js

代码语言:javascript
复制
{
    path: "apps",
    name: "apps",
    component: () => import("./components/protected/Apps"),
},
{
    path: "apps/:appid/regs",
    name: "regs",
    props: true,
    component: () => import("./components/protected/Regs"),
},
{
    path: "apps/:appid/regs/:regid/ids",
    name: "ids",
    props: true,
    component: () => import("./components/protected/Ids"),
},

Apps.vue

代码语言:javascript
复制
<template>
<table class="table table-striped mg-b-0">
    <thead>
        <tr>
            <th class="tx-left w-5">#</th>
            <th class="tx-left">Application</th>
            <th class="tx-left text-center w-5">Action</th>
        </tr>
    </thead>
    <tbody>
        <tr v-bind:key="index" v-for="(app, index) in apps">
            <td class="masked">{{index+1}}</td>
            <td>{{app.name}}</td>
            <td class="text-center">
                <router-link class="bg-white" :to="{ name: 'regs', params: { appid: app.id}}">
                    <i class="fa fa-border fa-eye" title="View Registries"/>
                </router-link>
            </td>
        </tr>
    </tbody>
</table>
</template>

Regs.vue

代码语言:javascript
复制
<template>
<template v-if="appid">
<table class="table table-striped mg-b-0">
    <thead>
        <tr>
            <th class="tx-left w-5">#</th>
            <th class="tx-left">Registry</th>
            <th class="tx-left text-center w-5">Action</th>
        </tr>
    </thead>
    <tbody>
        <tr v-bind:key="index" v-for="(reg, index) in regs">
            <td class="masked">{{index+1}}</td>
            <td>{{reg.name}}</td>
            <td class="text-center">
                <router-link class="bg-white" :to="{ name: 'ids', params: { appid: appid, regid: reg.id}}">
                    <i class="fa fa-border fa-eye" title="View Identities"/>
                </router-link>
            </td>
        </tr>
    </tbody>
</table>
</template>
</template>
<script>
export default {
    name: "Regs",
    props: ['appid'],
    ....
}

Ids.vue

代码语言:javascript
复制
<template>
<template v-if="appid && regid">
<table class="table table-striped mg-b-0">
    <thead>
        <tr>
            <th class="tx-left w-5">#</th>
            <th class="tx-left">Identity</th>
        </tr>
    </thead>
    <tbody>
        <tr v-bind:key="index" v-for="(id, index) in ids">
            <td class="masked">{{index+1}}</td>
            <td>{{id.name}}</td>
        </tr>
    </tbody>
</table>
</template>
</template>
<script>
export default {
    name: "Ids",
    props: ['appid','regid'],
    ....
}
</script>
EN

回答 1

Stack Overflow用户

发布于 2020-02-04 09:43:43

似乎您已经在使用道具-- appid‘和'regid’--在组件本身中道具还没有完全准备好。这就是为什么vue回复了警告。

在执行vfor之前,您可以先设置一个条件,以确保道具已经有了一个值。就像这个

Regs.vue

代码语言:javascript
复制
 <template v-if="appid">
       <tr v-bind:key="index" v-for="(reg, index) in regs">
                <td class="masked">{{index+1}}</td>
                <td>{{reg.name}}</td>
                <td class="text-center">
                    <router-link class="bg-white" :to="{ name: 'ids', params: { appid: appid, 
                      regid: reg.id}}">
                        <i class="fa fa-border fa-eye" title="View Identities"/>
                    </router-link>
                </td>
       </tr>
</template>

Ids.vue

代码语言:javascript
复制
<template v-if="appid &&  regid">
    <tr v-bind:key="index" v-for="(id, index) in ids">
            <td class="masked">{{index+1}}</td>
            <td>{{id.name}}</td>
    </tr>
</template>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60053524

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档