【问题标题】:Weird error when running a simple vue.js app运行简单的 vue.js 应用程序时出现奇怪的错误
【发布时间】:2017-04-01 14:48:21
【问题描述】:

我正在使用 vue.js 2.x,只是使用 webpack 设置了一个简单的应用程序。

当我在开发模式下启动应用程序时,我在 chrome 控制台中收到此错误并且页面上没有显示任何内容:

Uncaught TypeError: _vm._m is not a function(…)

服务器上没有错误(没有 webpack 错误)。

Routes.js

import Home from './components/Home.vue';
import Portfolio from './components/portfolio/Portfolio.vue';
import Stocks from './components/stocks/Stocks.vue';

export const routes = [{
    path: '/',
    components: Home
}, {
    path: '/portfolio',
    components: Portfolio
}, {
    path: '/stocks',
    components: Stocks
}]

ma​​in.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import { routes } from './routes'

Vue.use(VueRouter);

const router = new VueRouter({
  mode: 'history',
  routes
});

new Vue({
  el: '#app',
  router,
  render: h => h(App)
})

App.vue

<template>
    <div class="container">
        <router-view></router-view>
    </div>
</template>
<script>

    export default {

    }
</script>
<style>

</style>

Home.vue

<template>
    <h1>The home component</h1>
</template>

知道是什么原因造成的吗?

【问题讨论】:

  • 你能把webpack.config.js文件发到这里吗?到目前为止,你的我很好。

标签: webpack vue.js vue-router


【解决方案1】:

我可能不会在测试时尝试在您的 Vue 实例上使用 render

你应该有一个像index.html 这样的根文件,它为你的应用创建一个容器并调用应用组件:

#index.html
<div id="my-vue-app">
    <app></app>
</div>

然后编辑 main.js,将初始化 Vue 实例的方式替换为以下内容:

new Vue({
  components: {
    App
  },
  router
}).$mount('#my-vue-app')

【讨论】:

  • 我正在使用来自 udemy 课程的入门工具包,该课程已被数千人使用,此外,在幕后,vue 调用了渲染方法,因此真的没有差异
  • 不,显然我在路由定义中有错字:组件而不是组件
  • 也可以检查一下 vue-router 是不是最新版本:2.0.2
【解决方案2】:

所以,像往常一样,这是一个愚蠢的错误,我在路线定义中有错字, 我用components代替component

export const routes = [{
    path: '/',
   //should be component
    components: Home
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 2011-06-15
    • 2017-03-04
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    相关资源
    最近更新 更多