..."> ..."/> ..."> ...">

找不到Nuxt导出“默认”(导入为“ mod”)

JavaScript Vue.js

小胖Green

2020-03-24

我正在将Nuxt与Typescript一起使用。我创建以下组件:

<template>
    <div class="field">
        <label class="label" v-if="typeof label !== 'undefined'">{{ label }}</label>
        <div class="control">
            <textarea
                v-if="inputType === 'textarea'"
                class="textarea"
                @input="$emit('input', $event.target.value)"
            ></textarea>
            <input
                v-if="inputType === 'input'"
                :type="type"
                class="input"
                @input="$emit('input', $event.target.value)"
            >
        </div>
    </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator"

@Component({})
export default class AppInput extends Vue {
    @Prop({ type: String, required: false, default: "input" })
    inputType!: string

    @Prop({ type: String, required: false })
    label!: string

    @Prop({ type: String, required: false, default: "text" })
    type!: string
}
</script>

<style>
</style>

然后在中@/plugins/components.ts,我按如下所示导入组件:

import Vue from "vue"
import AppInput from "@/components/Forms/AppInput.vue"

Vue.component("AppInput", AppInput)

当我用Nuxt编译项目时,会抛出export 'default' (imported as 'mod') was not found错误。请帮忙!

第3394篇《找不到Nuxt导出“默认”(导入为“ mod”)》来自Winter(https://github.com/aiyld/aiyld.github.io)的站点

2个回答
乐米亚 2020.03.24

我使用以下tsconfig解决了:

{
    "compilerOptions": {
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "lib": ["esnext", "esnext.asynciterable", "dom"],
        "esModuleInterop": true,
        "experimentalDecorators": true,
        "allowJs": true,
        "sourceMap": true,
        "strict": false,
        "allowSyntheticDefaultImports": true,
        "noImplicitAny": false,
        "noEmit": true,
        "baseUrl": ".",
        "resolveJsonModule": true,
        "paths": {
            "~/*": ["./*"]
        },
        "types": ["@nuxt/vue-app", "@types/node", "@types/webpack-env"]
    }
}
米亚樱 2020.03.24

您将需要在vue文件中至少保留一个空的导出默认脚本,才能看到此错误。如果您没有任何导出默认语句,它将给出此错误/警告。

export default {

}

问题类别

JavaScript Ckeditor Python Webpack TypeScript Vue.js React.js ExpressJS KoaJS CSS Node.js HTML Django 单元测试 PHP Asp.net jQuery Bootstrap IOS Android