defineprops() must be a literal type or a reference to an interface or literal type

1.vue3打包遇到如下问题

defineprops() must be a literal type or a reference to an interface or literal type_第1张图片

2.分析

vue3 defineProps不支持使用外部导入的类型,会报错。

3.解决方法

就是直接在脚本标签区域写类型声明,然后引用即可。如下:

<script setup lang="ts">
// import type { Props } from './propsType'

type ValueType = {
    buzId: string,
    insuranceId: string,
    productId: string
} | undefined


 interface Props {
    formConfig: any[],
    formData: {
        ValueType?: ValueType,
        [P: string]: any
    },
    realTimeUrl: string,
    layout: string,
    productId?: number,
    planId?: number,
    scene?: number
}

const props = withDefaults(defineProps<Props>(), {
    formConfig: () => [],
    formData: () => ({}), // 表单数据
    realTimeUrl: '', // 实时提交的接口地址(业务逻辑)
    layout: 'inline',
    productId: undefined,
    planId: undefined,
    scene: undefined
})
<script/>

你可能感兴趣的:(vue,vue.js)