{"id":33356,"date":"2024-11-25T15:20:56","date_gmt":"2024-11-25T07:20:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/33356\/"},"modified":"2024-11-25T15:20:56","modified_gmt":"2024-11-25T07:20:56","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e5%bc%80%e5%8f%91%e4%b8%advar-that-this%e7%9a%84%e5%9f%ba%e6%9c%ac%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/33356\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2dvar that =this\u7684\u57fa\u672c\u7528\u6cd5"},"content":{"rendered":"<p>\u5728\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0cvar that =this\u7684\u58f0\u660e\u5f88\u5e38\u89c1\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4ee3\u7801\u5982\u4e0b\uff01<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u78011<\/strong><\/p>\n<pre>1  \/\/index.js  \n2  Page({  \n3   \n4   data: {  \n5    toastHidden: true,  \n6   },  \n7   \n8   loadData: function () {  \n9      var that = this\/\/\u8fd9\u91cc\u58f0\u660e\u4e86that\uff1b\u5c06this\u5b58\u5728that\u91cc\u9762  \n10     wx.request({  \n11       url: 'test.php',  \n12       data: {a: 'a', b: 'b'},  \n13       header: {  \n14        'content-type': 'application\/json'  \n15       },  \n16       success(res) {  \n17           that.setData({ toastHidden: false }) \/\/\u8fd9\u91cc\u4f7f\u7528\u4e86that\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u83b7\u53d6Page({})\u5bf9\u8c61  \n18        },  \n19      })  \n20    }  \n21  \n22  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4ee3\u7801\u4e2d\u7b2c9\u884c\u58f0\u660e\u4e86var that =this\uff1b\u7b2c17\u884c\u4f7f\u7528\u4e86that\u3002<\/p>\n<p>\u5982\u679c\u4e0d\u58f0\u660evar that =this\uff0c\u4e14that\u6539\u6210this\uff0c\u4ee3\u7801\u5982\u4e0b\uff01<br \/><strong>\u793a\u4f8b\u4ee3\u78012<\/strong><\/p>\n<pre>1  \/\/index.js  \n2   Page({  \n3  \n4    data: {  \n5     toastHidden: true,  \n6   },  \n7  \n8    loadData: function () {  \n9      wx.request({  \n10      url: 'test.php',  \n11      data: {a: 'a', b: 'b'},  \n12      header: {  \n13       'content-type': 'application\/json'  \n14      },  \n15      success(res) {  \n16        this.setData({ toastHidden: false })  \n17       },  \n18      })  \n19   }  \n20  \n21  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u65f6\u8fd0\u884c\u4ee3\u7801\u5c31\u4f1a\u62a5\u4ee5\u4e0b\u9519\u8bef\uff01<br \/><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/image\/679\/612\/588\/1592534296558858.png\" class=\"aligncenter\" title=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2dvar that =this\u7684\u57fa\u672c\u7528\u6cd5\u63d2\u56fe\" alt=\"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2dvar that =this\u7684\u57fa\u672c\u7528\u6cd5\u63d2\u56fe\" \/><\/p>\n<p>\u4ece\u62a5\u9519\u4e2d\u5f97\u77e5setData\u8fd9\u4e2a\u5c5e\u6027\u8bfb\u4e0d\u5230\uff0c\u4e3a\u4f55\u8bfb\u4e0d\u5230\uff1f\u8fd9\u8ddfthis\u5173\u952e\u5b57\u7684\u4f5c\u7528\u57df\u6709\u5173\uff01<\/p>\n<p><strong>this\u4f5c\u7528\u57df\u5206\u6790\uff1a<\/strong><\/p>\n<p>1.\u5728Page({})\u91cc\u9762\uff0cthis\u5173\u952e\u5b57\u6307\u4ee3Page({})\u6574\u4e2a\u5bf9\u8c61<\/p>\n<p>2.\u56e0\u6b64\u53ef\u4ee5\u901a\u8fc7this\u5173\u952e\u5b57\u8bbf\u95ee\u6216\u8005\u91cd\u65b0\u8bbe\u7f6ePage({})\u91ccdata\u7684\u53d8\u91cf<\/p>\n<p>3.\u7136\u800c\u5728loadData\u51fd\u6570\u4e2d\u4f7f\u7528\u4e86wx.request({})API\u8fd9\u4e2a\u65b9\u6cd5\u5bfc\u81f4\u5728wx.request({})\u91cc\u6ca1\u529e\u6cd5\u4f7f\u7528this\u6765\u83b7\u53d6Page({})\u5bf9\u8c61<\/p>\n<p>4.\u867d\u7136\u5728wx.request({})\u91cc\u6ca1\u6cd5\u4f7f\u7528this\u83b7\u53d6Page({})\u5bf9\u8c61\uff0c\u4f46\u662f\u53ef\u4ee5\u5728wx.request({})\u5916\u9762\u5148\u628athis\u5b58\u5728\u67d0\u4e2a\u53d8\u91cf\u4e2d\uff0c\u6240\u4ee5\u5c31\u6709\u4e86var that =this&nbsp;\u8fd9\u4e2a\u58f0\u660e\u3002\u6b64\u65f6that\u6307\u4ee3Page({})\u6574\u4e2a\u5bf9\u8c61\uff0c\u8fd9\u6837\u5b50\u5c31\u53ef\u4ee5\u5728wx.request({})\u91cc\u4f7f\u7528that\u8bbf\u95ee\u6216\u8005\u91cd\u65b0\u8bbe\u7f6ePage({})\u91ccdata\u7684\u53d8\u91cf<\/p>\n<p>\u63a8\u8350\u6559\u7a0b\uff1a\u300a\u300b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2dvar that =this\u7684\u57fa\u672c\u7528\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u4e2d\uff0cvar that =this\u7684\u58f0\u660e\u5f88\u5e38\u89c1\u3002\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u4ee3\u7801\u5982\u4e0b\uff01 \u793a\u4f8b\u4ee3\u78011 1 \/\/index.js 2 Page({ 3 4 data: { 5 toastHidden: true, 6 }, 7 8 loadData: function () { 9 var that = this\/\/\u8fd9\u91cc\u58f0\u660e\u4e86that\uff1b\u5c06this\u5b58\u5728that\u91cc\u9762 10 wx.request({ 11 url: &#8216;test.php&#8217;, 12 data: {a: &#8216;a&#8217;, b: &#8216;b&#8217;}, 13 header: { 14 &#8216;content-type&#8217;: &#8216;application\/json&#8217; 15 }, 16 success(res) { 17 that.setData({ toastHidden: false }) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-33356","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33356","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=33356"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/33356\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=33356"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=33356"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=33356"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}