首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >vue 3组合api props函数不能调用可能是“未定义”的对象

vue 3组合api props函数不能调用可能是“未定义”的对象
EN

Stack Overflow用户
提问于 2021-07-23 21:44:17
回答 1查看 111关注 0票数 0

我有一个名为sortSearch的属性,它是来自父调用者的函数或回调。

代码语言:javascript
复制
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'

代码语言:javascript
复制
     // Cannot invoke an object which is possibly 'undefined'.Vetur(2722)
      //props.sortSearch(s, state.currentSortDir);

通过我简短的谷歌搜索,我找到了非常有限的关于这方面的示例/文档,并感谢任何帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-01 12:26:22

您需要将此道具标记为必需的:

代码语言:javascript
复制
  props: {
    sortSearch: {
      type: Function as PropType<SortSearchInterface>,
      required: true
    },
  },
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68500197

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档