如何解决vue 3 组合 api props 函数无法调用可能是“未定义”的对象
我有一个名为 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
},},
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。