Vue和Node.js无法从“位置”导入文件模块“模块”

时间:2019-12-27 08:50:30

标签: javascript node.js vue.js import components

我正在尝试将vue组件加载到HTML文件中,但是出现以下错误:

  

错误:无法从'D:\ Dev \ project \ public \ js'中找到模块'./../ vue / modules / component-header'

有我的 index.html

...
<body>
    <section id="home-section">
        <component-header></component-header>
    </section>
</body>
...

index.js (已加载到index.html中)

import Header from './../vue/modules/component-header';

Vue.component('component-header', Header);

new Vue({
    el: '#home-section',
    render: h => h(Header)
});

还有我的 component-header.vue

<template>
    <header>Test</header>
</template>

<script>
    export default {
        name: "component-header"
    }
</script>

我也在使用 Browserify

let fs = require("fs");
let browserify = require("browserify");

browserify(["public/js/index.js"])
    .transform("babelify")
    .bundle()
    .pipe(fs.createWriteStream("public/dist/index.js"));

这是文件夹结构(父文件夹是“项目”):

structure

我试图修改 index.js 中的“导入”路径,但它没有任何改变。

0 个答案:

没有答案