【问题标题】:After updating from vue 2.1 to 2.5, vue stopped working从 vue 2.1 更新到 2.5 后,vue 停止工作
【发布时间】: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。

标签: vue.js vuejs2 vue-cli


【解决方案1】:

我遇到了类似的问题,更新也无缘无故停止了我的 Vue 应用程序,并且像您在这里遇到的那样说未定义。

简单的解决方案是在我的app.js 文件中注册时将.default 添加到我所有组件的末尾。

Vue.component('nav-container', require('./components/nav/nav-container.vue').default);

【讨论】:

    猜你喜欢
    • 2021-10-11
    • 2018-09-18
    • 2016-11-03
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多