首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >vue-路由器创建链接但pops控制台错误

vue-路由器创建链接但pops控制台错误
EN

Stack Overflow用户
提问于 2017-11-18 15:48:21
回答 1查看 194关注 0票数 0

有人能解释一下我为什么在控制台出错吗?

代码语言:javascript
运行
复制
app.js:12666 TypeError: Cannot read property 'uuid' of undefined
    at Proxy.render (app.js:95774)
    at VueComponent.Vue._render (app.js:15384)
    at VueComponent.updateComponent (app.js:13674)
    at Watcher.get (app.js:14017)
    at new Watcher (app.js:14006)
    at mountComponent (app.js:13678)
    at VueComponent.Vue$3.$mount (app.js:19232)
    at VueComponent.Vue$3.$mount (app.js:21567)
    at init (app.js:14980)
    at createComponent (app.js:16419)

但是我在我的页面上得到的链接是可以的吗?

Vue文件如下所示

代码语言:javascript
运行
复制
<template>
    <div class="main-container">
        <h1 class="page-title">Protocols</h1>

        <div class="wrapper">
            <router-link :to="`/protocol/${protocolListObject.protocol.uuid}/edit`" class="dropdown-item">Click to edit</router-link>
        </div>

        </div>
</template>


<script>
    import moment from 'moment'

    export default {

        data() {
            return {
                protocolListObject: {},
                error: {},
            }
        },
        created() {
            axios.post('/getSingleProtocol/:uuid')
                .then((response) => this.protocolListObject = JSON.parse(response.data))
                .catch(error => console.log(error.response));
        },
        mounted() {

        }
    }
</script>

app.js看起来像这样(我将移除路线和一些与此无关的东西,只是为了使它更短)

代码语言:javascript
运行
复制
window.Vue = require('vue');
import Vue from 'vue'
import VueRouter from 'vue-router'
import moment from 'moment'
Vue.use(VueRouter)
let ProtocolSummary = Vue.component('protocol-summary', require('./components/ProtocolSummary.vue'));
let ProtocolEdit = Vue.component('protocol-edit', require('./components/ProtocolEdit.vue'));

const routes = [
    { path: '/protocol/:uuid', component: ProtocolSummary },
    { path: '/protocol/:uuid/edit', component: ProtocolEdit },
]
const router = new VueRouter({
    mode: 'history',
    routes // short for `routes: routes`
})
Vue.prototype.moment = moment
const app = new Vue({
    router
}).$mount('#app');

但是当我加载页面时,我得到了一个我需要的UUID链接,但是控制台错误看起来很糟糕,我想摆脱它。

EN

Stack Overflow用户

回答已采纳

发布于 2017-11-18 16:12:12

yuriy在上面的评论中说,问题是,最初,我的变量是空的。从URL中添加变量解决问题(在vueJS文件中)

代码语言:javascript
运行
复制
        data() {
            return {
                protocolListObject: {
                    protocol: {
                        uuid: this.$route.params.uuid
                    }
                },
                error: {},
            }
        },
票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47367931

复制
相关文章

相似问题

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