Javascript 功能组件发出事件:表达式不可调用-Vue
具有渲染功能的功能组件:Javascript 功能组件发出事件:表达式不可调用-Vue,javascript,typescript,vue.js,Javascript,Typescript,Vue.js,具有渲染功能的功能组件: render(createElement, { listeners } { return createElement('div', { on: { click: () => { // issue is on this line const onItemClick: any = listeners['item-click'] onItemClick(1, 2, 3) } }
render(createElement, { listeners } {
return createElement('div', {
on: {
click: () => {
// issue is on this line
const onItemClick: any = listeners['item-click']
onItemClick(1, 2, 3)
}
}
})
}
如何正确键入onItemClick
,以避免出现错误:
const onItemClick: Function | Function[]
This expression is not callable.
No constituent of type 'Function | Function[]' is callable.ts(2349)
侦听器的签名
:
var listeners: {
[key: string]: Function | Function[];
}
尝试用
函数()
构造函数替换箭头函数
on: { click: function() { // do the stuff }}
使用类型断言解决了此问题:
const onItemClick = listeners['item-click'] as (val1: string, val2: string) => void
onItemClick('123, '456')
它说数组是不可调用的,检查array->call Eather call valueType断言是否不是一个真正的解决方案,似乎是一个解决方法。我想知道为什么类型是
Function | Function[]
。