为什么setData会无效,也不出错

gzwlj2001 2020-12-30 05:28:29
如题:console.log一直输出undefined,但输出e.detail.value又是对的,刚学小程序开发,想不明白 按网上说的 改成 var that = this 也没用

data: {
items: [
{ name: 'wx-auto', value: '记住密码,下次自动登录' },
],
strKHKey:"",
strwxtel:"",
boolwxtelEnabled:false,
strpw:"",
boolpwEnabled:false,
boolAuto:true
},

KHKeyInput:function(e){
this.setData({
strKHKey:e.detail.value
})
console.log("strKHKey:"+this.strKHKey)
},

...全文
3527 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
木头印象 2020-12-31
  • 打赏
  • 举报
回复
晕,没仔细看,之所以是undefined,是因为少了个data,应该是: console.log("strKHKey:",this.data.strKHKey)
木头印象 2020-12-31
  • 打赏
  • 举报
回复
console.log("strKHKey:"+that.strKHKey) ; 上面漏了个;号
木头印象 2020-12-31
  • 打赏
  • 举报
回复
data: { items: [ { name: 'wx-auto', value: '记住密码,下次自动登录' }, ], strKHKey:"", strwxtel:"", boolwxtelEnabled:false, strpw:"", boolpwEnabled:false, boolAuto:true }, KHKeyInput:function(e){ var that = this; that.setData({ strKHKey:e.detail.value }) console.log("strKHKey:"+that.strKHKey) },

3,143

社区成员

发帖
与我相关
我的任务
社区描述
微信开发即微信公众平台开发,将企业信息、服务、活动等内容通过微信网页的方式进行表现,通过二次开发可以将公众账号由一个媒体型营销工具转化成提供服务的产品。
社区管理员
  • 微信开发
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧