我有一个名为sortSearch的属性,它是来自父调用者的函数或回调。
type SortSearchInterface = (
currentSort: string,
currentSortDir: string
) => void;
export default defineComponent({
props: {
//sortSearch: {
//type: Function as PropType<(currentSort: string, currentSortDir: string)=> void>
// type: Function as PropType<SortSearchInterface>|undefined
// }
sortSearch: Function as PropType<SortSearchInterface>,
},
当使用attempting to call this function时,我得到以下错误:Cannot invoke an object which is possibly 'undefined'
// Cannot invoke an object which is possibly 'undefined'.Vetur(2722)
//props.sortSearch(s, state.currentSortDir);
通过我简短的谷歌搜索,我找到了非常有限的关于这方面的示例/文档,并感谢任何帮助。
发布于 2021-08-01 12:26:22
您需要将此道具标记为必需的:
props: {
sortSearch: {
type: Function as PropType<SortSearchInterface>,
required: true
},
},
https://stackoverflow.com/questions/68500197
复制相似问题