html52.com
我爱小程序-开发者交流社区

ts 使用 setData 编译报错

如标题

使用 this.setData({

    a: 1

})



Page({

data: {

    accountValue: ' '

},

onLoad () {

},

bindKeyInput (e: any) {

    this.setData({

    accountValue: e.detail.value

    })

}

})


miniprogram/pages/login/login.ts:10:9 - error TS2722: Cannot invoke an object which is possibly 'undefined'.


10         this.setData({

           ~~~~~~~~~~~~



Found 1 error.




请教一下



网友回复

Hush now丶:

问题找到了   在ts语法中 setData() 是可选   所以使用为     this.setData!({})    要加感叹号!

那个很帅的小白:

麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

真正的个人免签约支付接口

云免签H5支付