'YHLogin.vue' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.
如上异常出自下方的 code 定义变量的时候抛出.大致理解为TS未能导出/导入的文件视为旧脚本的文件并非模块;
<script setup lang="ts">
const handleOpen = (key: string, keyPath: string[]) => {
console.log(key, keyPath);
};
</script>
解决办法
根据提示将 ts 配置文件 tsconfig.json 中添加或修改 isolatedModules 的值为 false 即可.
{
"extends": "@vue/tsconfig/tsconfig.web.json",
"include": ["env.d.ts", "src/**/*", "src/**/*.vue"],
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
"isolatedModules": false, // 添加或修改该属性即可
},
"references": [
{
"path": "./tsconfig.config.json"
}
]
}
以上便是此次分享的全部内容,希望能对大家有所帮助!
网友评论