【发布时间】:2017-12-29 14:22:11
【问题描述】:
我最近从 vue 2.1 更新到 vue 2.5。
我已经使用vue-cli创建项目,然后将之前2.1项目的组件移动到src文件夹中。
之后我开始收到错误:
Uncaught TypeError: Cannot read property 'components' of undefined
at checkComponents (vue.esm.js?e1b2:1321)
at mergeOptions (vue.esm.js?e1b2:1442)
at mergeOptions (vue.esm.js?e1b2:1458)
at Vue$3.Vue._init (vue.esm.js?e1b2:4528)
at new Vue$3 (vue.esm.js?e1b2:4646)
at eval (main.js?3479:41)
at Object../src/main.js (app.js:5655)
at __webpack_require__ (app.js:679)
at fn (app.js:89)
at Object.0 (app.js:5928)
我的 main.js 如下:
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import { store } from './store'
import mixins from './mixins'
import VueRouter from 'vue-router'
import routes from './routes'
const router = new VueRouter({
routes: routes.routes
// mode: 'history'
})
/* eslint-disable no-new */
new Vue({
el: '#app',
router,
render: h => h(App),
store: store,
mixins: [mixins]
})
这里是请求的 App.vue 文件:
<template>
<div id="app">
<el-container>
<navbar v-if="loggedIn"></navbar>
<el-aside style="width:auto; z-index:9999; ">
<sidebar v-if="loggedIn"></sidebar>
</el-aside>
<el-main style="width:auto;">
<router-view></router-view>
</el-main>
</el-container>
</div>
</template>
<script>
import Sidebar from './page_components/Sidebar'
import Navbar from './page_components/Navbar'
export default {
components: {
Sidebar,
Navbar
}
}
我在 vue.esm.js 中的以下行中收到错误:
【问题讨论】:
-
你也可以分享文件./App吗?
-
@Manish 已更新。
-
我的直觉是您的一个或所有 mixin 定义不正确。如果您从 App 中删除
mixins: [mixins],您会收到错误消息吗? -
也可以试试
console.log(mixins)看看那个对象里有什么 -
谢谢。这有助于我需要在 Vue.mixin({}) 中添加 export.default。