如何使用打字稿在 vue3 设置脚本中导入类型?
How to import type in vue3 setup script with typescript?
我想将 <script setup>
功能与打字稿中的道具类型检查结合使用。
但是似乎 <script setup>
没有将 RouteRecordRaw 作为类型导入,而是作为值导入?
而如果我在vite中运行这段代码,浏览器控制台会打印出一个错误:
"Uncaught SyntaxError: The requested module '/node_modules/.vite/vue-router.js?v=52a879a7' does not provide an export named 'RouteRecordRaw'"
代码:
<script lang="ts" setup>
import { RouteRecordRaw } from "vue-router";
// VSCode will print an error: "RouteRecordRaw" only refers to a type, butisbeing used as a value here. (TS2693)
import { defineProps } from "vue";
const props = defineProps<{
routeList: Array<RouteRecordRaw>;
}>();
const renderRoutes = props.routeList;
</script>
使用这个:
import type { RouteRecordRaw } from "vue-router";
我想将 <script setup>
功能与打字稿中的道具类型检查结合使用。
但是似乎 <script setup>
没有将 RouteRecordRaw 作为类型导入,而是作为值导入?
而如果我在vite中运行这段代码,浏览器控制台会打印出一个错误:
"Uncaught SyntaxError: The requested module '/node_modules/.vite/vue-router.js?v=52a879a7' does not provide an export named 'RouteRecordRaw'"
代码:
<script lang="ts" setup>
import { RouteRecordRaw } from "vue-router";
// VSCode will print an error: "RouteRecordRaw" only refers to a type, butisbeing used as a value here. (TS2693)
import { defineProps } from "vue";
const props = defineProps<{
routeList: Array<RouteRecordRaw>;
}>();
const renderRoutes = props.routeList;
</script>
使用这个:
import type { RouteRecordRaw } from "vue-router";