作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 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/
我是一名优秀的程序员,十分优秀!