新手问下setdata问题?

小程序 文章 2021-01-22 12:01 386 0 全屏看文

AI助手支持GPT4.0

新手问下setdata问题?The novice asks about setdata?

新手问下setdata问题?
Page({  onLoad() {        var that = this;        wx.request({          url: 'https://****', //仅为示例,并非真实的接口地址          data: {            x: '',            y: ''          },          header: {            'content-type': 'application/json' // 默认值          },          success (res) {            console.log(res.data)            this.setdata({motto:'测试赋值'})     //报错了            //that.setdata({motto:'测试赋值'})  //报错了          }        })  }})这两个语句都报错了,提示“this.setData is not a function”, 我用this.setdata和that.setdata都不行,新手求助,谢谢!!

Page({  onLoad() { var that = this; wx.request ({URL: 'HTTPS: / / * *', / / for example only, not real interface address, data: {X: ', Y:'}, header: {content type ':'application / JSON' / / default value}, success (res) {console.log ( res.data )this.setdata ({motto: 'test assignment'}) / / error reported// that.setdata ({motto: 'test assignment'}) / / error})}) both statements report errors, indicating that“ this.setData Is not a function " this.setdata and that.setdata No way, novice help, thank you! !

回答:

默认²⁰²⁰:

this指向问题 你上面都把this赋值给that为啥就是不用呢? 自己找罪受?

大胖余:

this指向问题多学习, 变量名写的不正确 this.setData 多检查检查

自酌一杯酒:
that.setData({motto:'测试赋值'})

setData写错了, D大写。

-EOF-

AI助手支持GPT4.0