Vue3 defineProps 引入接口报错如何解决?
- 内容介绍
- 文章标签
- 相关推荐
本文共计275个文字,预计阅读时间需要2分钟。
在`setup`语法糖中使用`defineProps`时,若在定义类型时直接将接口暴露,可能会引发错误。问题相关代码如下:
typescriptinterface Props { /* ... */}
export { Props };
问题遇到的现象
在setup语法糖使用了defineProps,然而在定义类型的时候一旦将接口暴露出去引用就发生了报错
问题相关代码
interface Props { /* ... */ } export { type Props }
<script setup lang="ts"> import { Props } from '.' const props = defineProps<Props>() </script>
运行结果及报错内容
[@vue/compiler-sfc] type argument passed to defineProps() must be a literal type, or a reference to an interface or literal type.
我的解答思路和尝试过的方法
在组件中直接定义接口就不会报错,
我想要达到的结果
将接口封出去进行引用
以上就是解决vue3 defineProps 引入定义的接口报错的详细内容,更多关于vue3 defineProps 引入报错的资料请关注易盾网络其它相关文章!
本文共计275个文字,预计阅读时间需要2分钟。
在`setup`语法糖中使用`defineProps`时,若在定义类型时直接将接口暴露,可能会引发错误。问题相关代码如下:
typescriptinterface Props { /* ... */}
export { Props };
问题遇到的现象
在setup语法糖使用了defineProps,然而在定义类型的时候一旦将接口暴露出去引用就发生了报错
问题相关代码
interface Props { /* ... */ } export { type Props }
<script setup lang="ts"> import { Props } from '.' const props = defineProps<Props>() </script>
运行结果及报错内容
[@vue/compiler-sfc] type argument passed to defineProps() must be a literal type, or a reference to an interface or literal type.
我的解答思路和尝试过的方法
在组件中直接定义接口就不会报错,
我想要达到的结果
将接口封出去进行引用
以上就是解决vue3 defineProps 引入定义的接口报错的详细内容,更多关于vue3 defineProps 引入报错的资料请关注易盾网络其它相关文章!

