微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

vue路由引入配置报错(转)

引入路由配置文件index.js报如下错:

Error in beforeCreate hook: "TypeError: this._router.init is not a function"

Error in beforeCreate hook: "TypeError: this._router.init is not a function"

Error in render: "TypeError: Cannot read property 'matched' of undefined"

Cannot read property 'matched' of undefined

是因为把vue路由文件单独抽离出来后报错,vue解析文件正确,路由抽离引用也正确。组件都正确。问题是在vue路由JS文件中,暴露变量的格式有误。

错误的格式为:

export default {

router

}

使用这种格式 需要用变量的形式接收,如果你用的是import xx from '../'那么就错了

如果你是使用以上格式 那么正确引用格式为:import {xx} from '../'

当然我们也可以保留import xx from '../'的格式 那么vue路由暴露变量方式改为以下即可
export default router

格式必须如下统一:

格式一 变量形式 --暴露
export default {
router
}

--接收
import {router} from './xx.js'



格式二 直接暴露
 export default router

接收
import router from './xx.js'

原文链接https://www.jianshu.com/p/9b4ee17f2cba

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐