vue 3 组合 api 道具函数无法调用可能 'undefined' 的对象
vue 3 composition api props function Cannot invoke an object which is possibly 'undefined'
我有一个名为 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);
通过我简短的谷歌搜索,找到了非常有限的示例/文档,感谢任何帮助。
您需要根据需要标记此道具:
props: {
sortSearch: {
type: Function as PropType<SortSearchInterface>,
required: true
},
},
我有一个名为 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);
通过我简短的谷歌搜索,找到了非常有限的示例/文档,感谢任何帮助。
您需要根据需要标记此道具:
props: {
sortSearch: {
type: Function as PropType<SortSearchInterface>,
required: true
},
},