VUE 2:在另一个组件的<template>中引用VUE组件。模块未找到异常

时间:2017-04-20 13:34:27

标签: vue.js vuejs2 vue-component vuex

我一直在谷歌上搜索已经有一段时间了解为什么..我的模态组件在我的vieworder.vue组件中无法识别。

我收到了:

ERROR in ./~/babel-loader/lib!./~/vue-loader/lib/selector.js?
type=script&index=0!./src/components/ViewOrder.vue

Module not found: Error: Can't resolve './components/Modal.vue' in 
'C:\xxxxxx\xxxxxxxxx\src\components'

ViewOrder.vue - 使用模态:

<template>
    <div class="col-sm-10 col-sm-offset-1" v-if="order">
        <modal v-if="showModal" @close="showModal = false">
        </modal>   
    </div>
</template>

<script>

import * as types from '../store/mutationtypes'
import { mapGetters, mapActions } from 'vuex'
import Modal from './components/Modal.vue'

export default {
    name: 'ViewOrder',
    components: {
        'modal': Modal
    }
    ....

Modal.vue

<template>
    ....
</template>

<script>
    export default {
        name: "modal"
    }
</script>

Main.js - 参考:

....
import Modal from './components/Modal.vue'
import ViewOrder from './components/ViewOrder.vue'
....

1 个答案:

答案 0 :(得分:4)

import Modal from './components/Modal.vue'

应为import Modal from './Modal.vue'

您在components

内时已经在ViewOrder.vue文件夹中