首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Vue代码抛出错误,编辑器终端上没有默认导出

Vue代码抛出错误,编辑器终端上没有默认导出
EN

Stack Overflow用户
提问于 2022-09-09 12:41:17
回答 1查看 64关注 0票数 0

浏览器没有问题,我得到了所需的输出。但是为什么编辑终端会不断地显示这种情况呢?

任何帮助都将不胜感激。

无默认导出错误:

代码语言:javascript
复制
Module '"/vue3/src/components/TestIcon.vue"' has no default export.

我的部件看起来像这样。

TestIcon.vue

代码语言:javascript
复制
<template>
  <span v-html="svg" class="icon-wrapper" ref="iconWrapper"></span>
</template>    
<script setup lang="ts">
import type { tycon } from "test-icons";
import { computed, onMounted, ref } from "vue";
import { completeDataSet } from "test-icons";

const props = defineProps<{
  icon: tycon;
  class: string;
  color: string;
  height: string;
  width: string;
}>();
const iconPassed = completeDataSet.find((item) => item.name === props.icon);

const svg = computed(() => iconPassed?.data);

const iconWrapper = ref<HTMLElement | null>(null);

onMounted(() => {
  iconWrapper.value?.lastElementChild?.firstElementChild?.setAttribute(
    "class",
    props.class
  );

  iconWrapper.value?.firstElementChild?.setAttribute(
    "style",
    "width:" + props.width + "px;height:" + props.height + "px;"
  );

  iconWrapper.value?.firstElementChild?.firstElementChild?.setAttribute(
    "fill",
    props.color
  );
});
</script>

App.vue:

代码语言:javascript
复制
<template>
  <main>
    <TestIcon :icon="'icon_test'" :class="'tests'" :height="40" :width="40" />
  </main>
</template>
<script lang="ts">
import TestIcon from "@/components/TestIcon.vue";
export default {
  components: {
    TestIcon,
  }
};
</script>
EN

回答 1

Stack Overflow用户

发布于 2022-10-05 01:13:47

如果您使用的是vue-cli,那么检查shims-vue.d.ts文件是否存在内容:

代码语言:javascript
复制
/* eslint-disable */
declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}

或者,如果您使用的是vite,请签出env.d.ts文件,内容如下:

代码语言:javascript
复制
/// <reference types="vite/client" />

/* eslint-disable */
declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73662317

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档