【问题标题】:Importing Vue Component导入 Vue 组件
【发布时间】:2018-01-16 13:00:54
【问题描述】:

我有一个注册的 Vue 组件:

Vue.component('logo', function (resolve) {require(['./components/layout/Logo.vue'], resolve)});

组件本身定义为:

<template>
    <div>
        <div class="title">
            <a href="/">
                <h1>Welcome to my Site!</h1>
            </a>
        </div>
        <navigation></navigation>
    </div>
</template>

<style scoped>
    h1 {
        text-decoration: underline;
        text-align: center;
        color: #000000;
    }

</style>

<script>
    import Navigation from './Navigation.vue';

    export default {
        data() {
            return {
                msg:'hello vue'
            }
        },
        components: {
            Navigation
        }
    }

</script>

Logo.vueNavigation.vue 在同一目录中。 Webpack 运行时不会报错。

当网站加载但报告控制台错误时:

app.js:142 TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (app.js:50)
    at app.js:883
    at <anonymous>
__webpack_require__.oe @ app.js:142
Promise rejected (async)
(anonymous) @ app.js:883
resolveAsyncComponent @ app.js:33890
createComponent @ app.js:35368
_createElement @ app.js:35578
createElement @ app.js:35517
vm._c @ app.js:35857
(anonymous) @ VM449:2
Vue._render @ app.js:35909
updateComponent @ app.js:34319
get @ app.js:34662
Watcher @ app.js:34651
mountComponent @ app.js:34323
Vue$3.$mount @ app.js:39644
Vue$3.$mount @ app.js:41847
Vue._init @ app.js:36017
Vue$3 @ app.js:36102
(anonymous) @ app.js:886
__webpack_require__ @ app.js:50
(anonymous) @ app.js:857
__webpack_require__ @ app.js:50
(anonymous) @ app.js:145
(anonymous) @ app.js:148
app.js:50 Uncaught (in promise) TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (app.js:50)
    at app.js:883
    at <anonymous>

当我用Vue.component('navigation', function (resolve) {require(['./components/layout/Navigation.vue'], resolve)});全局注册第二个组件时,无论我是否使用该组件,都会出现同样的错误。

【问题讨论】:

    标签: javascript laravel vue.js vue-component


    【解决方案1】:

    我的webpack.mix.js 包含:

    mix.webpackConfig({
        output: {
            filename: "js/[id].js"
        }
    });
    

    删除它后,我能够正确加载。这是为了将输出的块文件移动到js/目录,但显然是错误的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-23
      • 2017-10-11
      • 1970-01-01
      • 2017-05-18
      • 2020-06-18
      • 2019-02-03
      • 1970-01-01
      • 2020-10-18
      相关资源
      最近更新 更多