gpt4 book ai didi

typescript - Vue 3 : Setup Script, TS问题: "An import declaration can only be used in a namespace or module."

转载 作者:行者123 更新时间:2023-12-05 02:33:57 26 4
gpt4 key购买 nike

在 Vue 3 中使用带有 typescript 的设置脚本时,我在 vscode 中收到一条错误消息:“导入声明只能在 namespace 或模块中使用。”

外部库和自己的 vue 组件会发生这种情况。

我。即:

<script setup lang="ts">
// ...

// ASSETS
import SvgCircle from '@/assets/img/IconsSvg/SvgCircle.vue';

// MODELS
import { IApiParams } from '@/models/api/apiparams.interface
// import { EBp } from '@/models/enum/baseParams.enum';

// LIBS
import justSafeGet from 'just-safe-get';

// ...
</script>

所有这些都在 vscode 中出现红线。其他如从 vue 或 vue-router 导入或自己的可组合项不会出现红线。我找不到有助于修复它的方法。

有人明白这一点并有线索吗?

最佳答案

通常,您应该先导入。

<script setup lang="ts">
import SvgCircle from '@/assets/img/IconsSvg/SvgCircle.vue'; // ASSETS
import { EBp } from '@/models/enum/baseParams.enum'; // MODELS
import justSafeGet from 'just-safe-get'; // LIBS
... // Any code here
</script>

关于typescript - Vue 3 : Setup Script, TS问题: "An import declaration can only be used in a namespace or module.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70851447/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com