【问题标题】:How to import type in vue3 setup script with typescript?如何使用打字稿在 vue3 设置脚本中导入类型?
【发布时间】:2021-07-19 12:06:35
【问题描述】:

我想使用<script setup> 功能和打字稿中的道具类型检查。 但似乎<script setup> 没有将 RouteRecordRaw 作为类型导入,而是作为值导入? 如果我在 vite 中运行这段代码,浏览器控制台会打印一个错误:

“未捕获的 SyntaxError:请求的模块 '/node_modules/.vite/vue-router.js?v=52a879a7' 未提供名为 '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>

【问题讨论】:

    标签: typescript vuejs3 vite


    【解决方案1】:

    使用这个:

    import type { RouteRecordRaw } from "vue-router";
    

    More info

    【讨论】:

      猜你喜欢
      • 2021-05-12
      • 2018-05-24
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 2022-01-19
      • 2021-09-14
      • 2022-12-20
      相关资源
      最近更新 更多