cannot read property 'name' of undefined

来源:5-6 开发微信网页 App 的导航组件

jessezwd

2017-11-05

http://img.mukewang.com/szimg/59fefb590001553906040421.jpg

写回答

1回答

Scott

2017-11-06

感觉是路由这里失败,前置流程中哪个环节出问题了,光从这个代码上,还不太好定位。


这是我的代码,你比对下,是不是都一致的,如果一致的话,问题应该是出在前面的环节中,比如集成 nav 的地方:


<template>
  nav#nav(v-if='navVisble')
    nuxt-link(v-for='(item, index) in navList' :to='item.path' :key='index') 
      div(v-if='index === 0')
        img(v-if='activeRoute !== item.name' src='~static/img/home.png')
        img(v-else src='~static/img/home-selected.png')
      div(v-else-if='index === 1')
        img(v-if='activeRoute !== item.name' src='~static/img/shopping.png')
        img(v-else src='~static/img/shopping-selected.png')
      div(v-else)
        img(v-if='activeRoute !== item.name' src='~static/img/user.png')
        img(v-else src='~static/img/user-selected.png')
      p {{item.text}}
</template>
<script>
export default {
  data () {
    return {
      navList: [
        {
          'path': '/',
          'name': 'index',
          'text': '冰火脸谱'
        },
        {
          'path': '/shopping',
          'name': 'shopping',
          'text': '周边手办'
        },
        {
          'path': '/user',
          'name': 'user',
          'text': '我的账户'
        }
      ]
    }
  },
  computed: {
    activeRoute () {
      return this.$route.name
    },
    navVisble () {
      return ['index', 'shopping', 'user'].indexOf(this.activeRoute) > -1
    }
  }
}
</script>
<style src='~static/sass/nav.sass'></style>


0
2
jessezwd
已解决。错误原因是,nav集成时,div没有缩进,与nuxt-link平齐。将div缩进就可以了。
2017-11-07
共2条回复

开发微信全家桶项目Vue/Node/MongoDB高级技术栈全覆盖

Nuxt/Vue SSR + Koa2 跨栈开发微信公众号+小程序

989 学习 · 401 问题

查看课程