简体   繁体   English

VueJS组件导入失败

[英]VueJS Component import failed

I have a simple demo I wanna try out to learn more about VueJS components. 我有一个简单的演示,我想尝试了解有关VueJS组件的更多信息。 But when I load my page, I receive the error: Unexpected Token Import, in this line 但是,当我加载页面时,在此行中收到错误:意外的令牌导入

import GISView from './components/GISView.vue'; 从'./components/GISView.vue'导入GISView;

when I remove this, GISView is not defined. 当我删除它时,未定义GISView。 I use Laravel 5.4 and webpack for compiling the scripts. 我使用Laravel 5.4和webpack来编译脚本。 Why is the component not found? 为什么找不到组件?

Main.js Main.js

import GISView from './components/GISView.vue';

window.Vue = Vue;
window.Event = new class {
    constructor() {
        this.Vue = new Vue();
    }

    fire(event, data = null) {
        this.Vue.$emit(event, data);
    }

    listen(event, callback) {
        this.Vue.$on(event, callback);
    }
};

window.app = new Vue({
    el: '#app',
    components: {
        GISView: GISView
    },
    data: {
    },
    methods: {
        init: function() {
            this.$broadcast('MapsApiLoaded');
        }
    }
});

GISView.vue GISView.vue

<script>
    import GoogleMaps from '../mixins/GoogleMaps.js';

    export default {
        mixins: [GoogleMaps]
    }
</script>

I really got stuck for hours on this because just by the code, it should work I would say. 我确实为此花了几个小时,因为仅凭代码,它就可以正常工作。

您没有使用像vueify之类的适当解析器来正确解析webpack / gulp脚本中的.vue文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM