cannot read property 'name' of undefined
来源:5-6 开发微信网页 App 的导航组件

jessezwd
2017-11-05
写回答
1回答
-
感觉是路由这里失败,前置流程中哪个环节出问题了,光从这个代码上,还不太好定位。
这是我的代码,你比对下,是不是都一致的,如果一致的话,问题应该是出在前面的环节中,比如集成 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>
022017-11-07
相似问题