javascript - Vue 路由器 - 命名路由缺少参数

标签 javascript vue.js vue-router

我该如何解决这个问题。

我有一个按钮,可以将我链接到关于我创建的对象的 View 。例如

   <router-link :to="{ name:DetailView,
                       params:{ id: detail.id}
                     }
                @click="createDetail()> Create Detail
   </router-link>

并且在我的组件中 detail 是在后端请求之后设置的:

detail:Detail;

createDetail(){
    makeBackendCall().then(detail=>{
        this.detail=detail
    })
}

这是我收到的警告/错误:

[vue-router] missing param for named route "name:DetailView":
Expected "id" to match "[^\/]+?", but received ""

显然 detail 组件还没有加载。有什么我想念的吗?

最佳答案

您应该制作一个普通的 html 按钮,然后在制作您的后端对象(并使用 css 设置按钮样式)后手动重定向用户

    <button @click="createDetail()"> Create Detail
    </button>
    createDetail(){
        makeBackendCall().then(detail=>{
            this.$router.push({
                name: DetailView,
                params: {
                    id: detail.id
                }
            })
        })
    }

在上面的代码中,$router 是指向当前事件 Vue 路由器的链接,and there are also other methods you can call on it, to do differend things

关于javascript - Vue 路由器 - 命名路由缺少参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54960185/

相关文章:

firebase - 在 Vue.js 中使用 Firebase auth/login 时,Firebase 的回调如何在 Vue 应用程序中设置数据?

javascript - Vue.js img src 连接变量和文本

javascript - 视觉 : Getting the router instance in children components

javascript - js无法访问Vue

vue.js - [Vue路由器警告] : No match found for location with path

javascript - 我无法让 pagify.js 工作

java - 如何转义url中的#符号?

javascript - Vue2 在刷新任何页面时重定向到主页

javascript - 删除 html 自动对焦使用 javascript/jquery

javascript - Algoliaplaces.js 完整表格和 map 链接