{"id":69161,"date":"2022-10-02T12:42:55","date_gmt":"2022-10-02T04:42:55","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=69161"},"modified":"2022-11-02T00:44:32","modified_gmt":"2022-11-01T16:44:32","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e6%8a%a5%e9%94%99%ef%bc%9atypeerror-cannot-read-property-setdata-of-undefined%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2022\/10\/02\/69161.htm","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u62a5\u9519\uff1aTypeError: Cannot read property \u2018setData\u2019 of undefined\u89e3\u51b3\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u5728\u5b8c\u6210\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u4e00\u4e2a\u529f\u80fd\u65f6\uff0c\u5076\u7136\u95f4\u62a5\u4e86\u4e00\u4e2a\u9519\u8bef\u3002<br>\u9519\u8bef\u4fe1\u606f\u662f\uff1aTypeError: Cannot read property \u2018setData\u2019 of undefined\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u51fa\u9519\u4ee3\u7801<\/h1>\n\n\n\n<p>\u6bcf\u5f53\u6211\u6267\u884chomework\u8fd9\u4e2a\u51fd\u6570\u65f6\uff0c\u6211\u53d1\u9001\u4e00\u4e2arequest\u8bf7\u6c42\uff0c\u5c06\u83b7\u53d6\u7684\u6570\u636e\u5b58\u5bfc\u672c\u5730\u7684<a rel=\"nofollow\" href=\"https:\/\/so.csdn.net\/so\/search?q=%E6%95%B0%E7%BB%84&amp;spm=1001.2101.3001.7020\" target=\"_blank\" rel=\"noreferrer noopener\">\u6570\u7ec4<\/a>\u4e2d\u3002\u6545\u6211\u5728sucess:function(res){}\u4e2d\u4f7f\u7528\u4e86this.setData({})\u3002<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">  homework: function () {\n    if (this.data.homeworkpageFlag == false) {\n      console.log(this)\n      this.setData({\n        homeworkpageFlag: true,\n        saypageFlag: false,\n        exampageFlag: false,\n      })\n    }\n    wx.request({\n      url: '\u67d0url hhhhh',\n      data: {\n        student_id: '\u67d0\u5b66\u53f7',\n      },\n      method: 'POST',\n      header: {\n        'content-type': 'application\/x-www-form-urlencoded'\n      },\n      success: function(res) {\n        console.log(res.data)\n        this.setData({\n          homeworkNoCompleteList: res.data.data.homeworkNoCompleteList\n        })\n      }\n    })\n\n  },\n\n<\/pre>\n\n\n\n<p>\u7406\u60f3\u5f88\u7f8e\u597d\uff0c\u4f46\u662f\u6bcf\u6b21\u6267\u884c\u5c31\u4f1a\u62a5\u4e0a\u9762\u7684\u9519\u8bef\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\"><a><\/a><a><\/a>\u89e3\u51b3\u65b9\u6848<\/h1>\n\n\n\n<ol class=\"wp-block-list\"><li>var that = this;<\/li><li>ES6\u7684\u7bad\u5934\u51fd\u6570<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a><\/a>\u65b9\u6848\u4e00\u3001var that = this\uff1b<\/h2>\n\n\n\n<p>\u6dfb\u52a0 var that = this\uff1b\u5e76\u628asucess\u4e2d\u7684this.setData\u6539\u6210that.setData<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">homework: function () {\n    if (this.data.homeworkpageFlag == false) {\n      console.log(this)\n      this.setData({\n        homeworkpageFlag: true,\n        saypageFlag: false,\n        exampageFlag: false,\n      })\n    }\n    \/\/\u6dfb\u52a0var that = this\n    var that = this;\n    wx.request({\n      url: 'https:\/\/fanzaixuexi.applinzi.com\/public\/index.php\/index\/GetInformation\/get_all_assignment',\n      data: {\n        student_id: '\u67d0\u5b66\u53f7',\n      },\n      method: 'POST',\n      header: {\n        'content-type': 'application\/x-www-form-urlencoded'\n      },\n      success: function(res) {\n        console.log(res.data)\n        \/\/\u6539\u6210\u4e86that.setData\n        that.setData({\n          homeworkNoCompleteList: res.data.data.homeworkNoCompleteList\n        })\n      }\n    })\n  },\n\n<\/pre>\n\n\n\n<p>\u6210\u529f\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a><a><\/a>\u65b9\u6848\u4e8c\u3001ES6\u7bad\u5934\u51fd\u6570\uff1b<\/h2>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">  homework: function () {\n    if (this.data.homeworkpageFlag == false) {\n      console.log(this)\n      this.setData({\n        homeworkpageFlag: true,\n        saypageFlag: false,\n        exampageFlag: false,\n      })\n    }\n    wx.request({\n      url: '\u67d0url',\n      data: {\n        student_id: '\u67d0id',\n      },\n      method: 'POST',\n      header: {\n        'content-type': 'application\/x-www-form-urlencoded'\n      },\n      success: (res)=> {\n        console.log(res.data)\n        \/\/ var that = this;\n        this.setData({\n           \/\/ \u6211\u8981\u83b7\u53d6\u7684\u6570\u636e\n        })\n        console.log(this.data.homeworkYesCompleteList.length)\n      }\n    })\n\n  },\n<\/pre>\n\n\n\n<p>\u628a success:function(res){}\u6539\u6210 success:(res)=&gt;{}<br>\u5c31\u53ef\u4ee5\u5927\u5927\u65b9\u65b9\u5730\u4f7f\u7528 this.setData\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5b8c\u6210\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u4e00\u4e2a\u529f\u80fd\u65f6\uff0c\u5076\u7136\u95f4\u62a5\u4e86\u4e00\u4e2a\u9519\u8bef\u3002\u9519\u8bef\u4fe1\u606f\u662f\uff1aTypeError: Cannot read property \u2018setData\u2019 of undefined\u3002 \u51fa\u9519\u4ee3\u7801 \u6bcf\u5f53\u6211\u6267\u884chomework\u8fd9\u4e2a\u51fd\u6570\u65f6\uff0c\u6211\u53d1\u9001\u4e00\u4e2arequ&#8230;<\/p>\n","protected":false},"author":1,"featured_media":69163,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,1],"tags":[421,600,398,363],"topic":[],"class_list":["post-69161","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wx","category-technology","tag-setdata","tag-undefined","tag-398","tag-363"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/69161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=69161"}],"version-history":[{"count":2,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/69161\/revisions"}],"predecessor-version":[{"id":69164,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/69161\/revisions\/69164"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media\/69163"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=69161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=69161"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=69161"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=69161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}