{"id":1529,"date":"2023-03-25T15:09:46","date_gmt":"2023-03-25T07:09:46","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1529"},"modified":"2023-04-27T21:43:55","modified_gmt":"2023-04-27T13:43:55","slug":"summary-of-wechat-mini-program-development-experience","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/summary-of-wechat-mini-program-development-experience\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u5f00\u53d1\u7ecf\u9a8c\u603b\u7ed3"},"content":{"rendered":"<h2>\u53c2\u6570\u4f20\u503c\u7684\u65b9\u6cd5<\/h2>\n<h3>data-id<\/h3>\n<p>\u53ef\u4ee5\u7ed9HTML\u5143\u7d20\u6dfb\u52a0<code>data-*<\/code>\u5c5e\u6027\u6765\u4f20\u9012\u6211\u4eec\u9700\u8981\u7684\u503c<\/p>\n<p><!-- more --><\/p>\n<p>\uff081\uff09\u8bbe\u7f6edata-id<\/p>\n<pre><code class=\"language-html\">&lt;view class=&quot;block&quot; bindtap=&quot;playTap&quot; data-id=&quot;{{modle.id}}&quot;&gt;<\/code><\/pre>\n<p>\uff082\uff09\u53d6\u503c + \u4f20\u503c<\/p>\n<pre><code class=\"language-javascript\">playTap: function(e) {\n  const dataset = e.currentTarget.dataset\n  wx.navigateTo({\n    url: &#039;..\/play\/index?id=&#039; + dataset.id\n  })\n  console.log(dataset.id);\n}<\/code><\/pre>\n<p>\uff083\uff09\u53d6\u503c<\/p>\n<pre><code class=\"language-javascript\">onLoad: function (param) {\n  \/\/\u9875\u9762\u521d\u59cb\u5316\n  this.setData({\n    currentId: param.id\n  })\n}<\/code><\/pre>\n<blockquote>\n<p>\u4f7f\u7528data-\u6ce8\u610f\u4e8b\u9879\uff1a<code>data-*<\/code>\u540d\u79f0\u4e0d\u80fd\u6709\u5927\u5199\u5b57\u6bcd\uff0c<code>data-*<\/code>\u5c5e\u6027\u4e2d\u4e0d\u53ef\u4ee5\u5b58\u653e\u5bf9\u8c61<\/p>\n<\/blockquote>\n<h3>\u8bbe\u7f6eid \u7684\u65b9\u6cd5\u6807\u8bc6\u6765\u4f20\u503c<\/h3>\n<p>\u4f7f\u7528\u65b9\u6cd5\u8bf4\u660e: <\/p>\n<p>\uff081\uff09\u8bbe\u7f6eid<\/p>\n<pre><code class=\"language-html\">&lt;view bindtap=&quot;playTap&quot; id=&quot;{{modle.id}}&quot;&gt;<\/code><\/pre>\n<p>\uff082\uff09\u53d6\u503c<\/p>\n<p>\u901a\u8fc7<code>e.currentTarget.id<\/code>\u83b7\u53d6\u8bbe\u7f6e\u7684id\u7684\u503c\uff0c\u7136\u540e\u901a\u8fc7\u8bbe\u7f6e\u5168\u5c40\u5bf9\u8c61\u7684\u65b9\u5f0f\u6765\u4f20\u9012\u6570\u503c<\/p>\n<h3>\u5728navigator\u4e2d\u6dfb\u52a0\u53c2\u6570\u4f20\u503c<\/h3>\n<p>\uff081\uff09\u4f20\u503c\uff1a\u5728navigator\u7684\u5c5e\u6027url\u540e\u62fc\u63a5?id(\u53c2\u6570\u540d)=\u8981\u4f20\u9012\u7684\u503c\uff08\u5982\u679c\u591a\u4e2a\u53c2\u6570\u7528&amp;\u5206\u5f00 ?name1=value1&amp;name2=value2\uff09<\/p>\n<pre><code class=\"language-html\">&lt;navigator url=&quot;..\/my\/my?id={{item.id}}&quot; wx:for=&quot;{{modles}}&quot;&gt;<\/code><\/pre>\n<p>\uff082\uff09\u53d6\u503c<\/p>\n<pre><code class=\"language-javascript\">onLoad (params) {\n  app.fetch(API.detail + params.id, (err, data) =&gt; {\n  })\n}<\/code><\/pre>\n<h2>\u6570\u636e\u8bf7\u6c42\u5c01\u88c5<\/h2>\n<p>\uff081\uff09\u5c06\u6240\u6709\u7684\u63a5\u53e3\u653e\u5728\u7edf\u4e00\u7684js\u6587\u4ef6\u4e2d\u5e76\u5bfc\u51fa<\/p>\n<pre><code class=\"language-javascript\">const api = {\n  api1: &#039;https:\/\/url1&#039;,\n  api2: &#039;https:\/\/url2&#039;,\n  api3: &#039;https:\/\/url3&#039;,\n  .....\n}\nmodule.exports = api<\/code><\/pre>\n<p>\uff082\uff09\u5728app.js\u4e2d\u521b\u5efa\u5c01\u88c5\u8bf7\u6c42\u6570\u636e\u7684\u65b9\u6cd5<\/p>\n<pre><code class=\"language-javascript\">fetch(url, data, callback) {\n  wx.request({\n    url,\n    data: data,\n    header: {\n      &#039;Content-Type&#039;: &#039;application\/json&#039;\n    },\n    success(res) {\n      callback(res.data, null)\n    },\n    fail(e) {\n      callback(null, e)\n    }\n  })\n}<\/code><\/pre>\n<p>\uff083\uff09\u5728\u5b50\u9875\u9762\u4e2d\u8c03\u7528\u5c01\u88c5\u7684\u65b9\u6cd5\u8bf7\u6c42\u6570\u636e<\/p>\n<pre><code class=\"language-javascript\">import API from &quot;..\/..\/api\/api.js&quot;\nconst app = getApp()\nconst conf = {\n  data: {\n    title:&#039;\u6b63\u5728\u62fc\u547d\u52a0\u8f7d\u4e2d...&#039;,\n    loadding:true\n  },\n  onLoad () {\n    app.fetch(API.api1, {}, (data, err) =&gt; {\n    })\n  }\n}<\/code><\/pre>\n<h2>\u4f7f\u7528\u6a21\u677f<\/h2>\n<p>\uff081\uff09\u5b9a\u4e49\u6a21\u677f:name\u8bbe\u7f6e\u6a21\u677f\u7684\u540d\u5b57<\/p>\n<pre><code class=\"language-html\">&lt;template name=&quot;cell&quot;&gt;\n  &lt;view class=&quot;item&quot;&gt;\n  &lt;\/view&gt;\n&lt;\/template&gt;<\/code><\/pre>\n<p>\uff082\uff09\u4f7f\u7528\u6a21\u677f<\/p>\n<p>\u9996\u5148\u5f15\u5165\u6a21\u677f<\/p>\n<pre><code class=\"language-html\">&lt;import src=&quot;..\/..\/common\/cell.wxml&quot; \/&gt;<\/code><\/pre>\n<p>\u7136\u540e\u4f7f\u7528\u6a21\u677fis\u8c03\u7528\u6307\u5b9aname\u7684\u6a21\u677f\uff0c\u901a\u8fc7data\u4f20\u9012\u9700\u8981\u7684\u6570\u636e<\/p>\n<pre><code class=\"language-html\">&lt;template is=&quot;cell&quot; data=&quot;{{item}}&quot;&gt;&lt;\/template&gt;<\/code><\/pre>\n<h2>Array\u6bd4\u8f83\u597d\u7528\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/h2>\n<ul>\n<li>Array.isArray() \u65b9\u6cd5\u7528\u6765\u5224\u65ad\u67d0\u4e2a\u503c\u662f\u5426\u4e3aArray\u3002\u5982\u679c\u662f\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002<\/li>\n<li>concat() \u65b9\u6cd5\u5c06\u4f20\u5165\u7684\u6570\u7ec4\u6216\u975e\u6570\u7ec4\u503c\u4e0e\u539f\u6570\u7ec4\u5408\u5e76,\u7ec4\u6210\u4e00\u4e2a\u65b0\u7684\u6570\u7ec4\u5e76\u8fd4\u56de.<\/li>\n<li>forEach() \u65b9\u6cd5\u5bf9\u6570\u7ec4\u7684\u6bcf\u4e2a\u5143\u7d20\u6267\u884c\u4e00\u6b21\u63d0\u4f9b\u7684\u51fd\u6570(\u56de\u8c03\u51fd\u6570)\u3002<\/li>\n<li>join() \u65b9\u6cd5\u5c06\u6570\u7ec4\u4e2d\u7684\u6240\u6709\u5143\u7d20\u8fde\u63a5\u6210\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002<\/li>\n<li>keys() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\u7d22\u5f15\u7684\u8fed\u4ee3\u5668\u3002<\/li>\n<li>map() \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u7531\u539f\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u8c03\u7528\u4e00\u4e2a\u6307\u5b9a\u65b9\u6cd5\u540e\u7684\u8fd4\u56de\u503c\u7ec4\u6210\u7684\u65b0\u6570\u7ec4<\/li>\n<li>pop() \u65b9\u6cd5\u5220\u9664\u4e00\u4e2a\u6570\u7ec4\u4e2d\u7684\u6700\u540e\u7684\u4e00\u4e2a\u5143\u7d20\uff0c\u5e76\u4e14\u8fd4\u56de\u8fd9\u4e2a\u5143\u7d20\u3002<\/li>\n<li>push() \u65b9\u6cd5\u6dfb\u52a0\u4e00\u4e2a\u6216\u591a\u4e2a\u5143\u7d20\u5230\u6570\u7ec4\u7684\u672b\u5c3e\uff0c\u5e76\u8fd4\u56de\u6570\u7ec4\u65b0\u7684\u957f\u5ea6\uff08length \u5c5e\u6027\u503c\uff09\u3002<\/li>\n<li>toString() \u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u8868\u793a\u6307\u5b9a\u7684\u6570\u7ec4\u53ca\u5176\u5143\u7d20\u3002<\/li>\n<\/ul>\n<h2>\u5bf9\u8c61Object\u5e38\u7528\u65b9\u6cd5<\/h2>\n<h3>\u521d\u59cb\u5316<\/h3>\n<pre><code class=\"language-javascript\">var obj = []\nvar obj = new obj()\nvar obj = Object.create(null)<\/code><\/pre>\n<h3>\u5b57\u5178\u6dfb\u52a0\u5143\u7d20<\/h3>\n<pre><code class=\"language-javascript\">dic[&#039;key&#039;] = &#039;value&#039;<\/code><\/pre>\n<h3>\u5b57\u5178\u5220\u9664key<\/h3>\n<pre><code class=\"language-javascript\">delete dic[\u201ckey\u201d]<\/code><\/pre>\n<h3>\u5b57\u5178\u6e05\u7a7a\u8bcd\u6240\u6709\u6761\u76ee<\/h3>\n<pre><code class=\"language-javascript\">dic.clear()<\/code><\/pre>\n<h3>\u5220\u9664\u5bf9\u8c61<\/h3>\n<pre><code>delete obj<\/code><\/pre>\n<h3>\u67e5\u770b\u5bf9\u8c61\u6240\u6709\u5c5e\u6027<\/h3>\n<pre><code class=\"language-javascript\">Object.keys(obj)<\/code><\/pre>\n<p>\u5bf9\u8c61\u7684\u6240\u6709\u952e\u540d\u90fd\u662f\u5b57\u7b26\u4e32\uff0c\u6240\u4ee5\u52a0\u4e0d\u52a0\u5f15\u53f7\u90fd\u53ef\u4ee5\uff0c\u5982\u679c\u952e\u540d\u662f\u6570\u503c\uff0c\u4f1a\u88ab\u81ea\u52a8\u8f6c\u4e3a\u5b57\u7b26\u4e32\u3002\u4f46\u662f\uff0c\u5982\u679c\u952e\u540d\u4e0d\u7b26\u5408\u6807\u8bc6\u540d\u7684\u6761\u4ef6\uff08\u6bd4\u5982\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e3a\u6570\u5b57\uff0c\u6216\u8005\u542b\u6709\u7a7a\u683c\u6216\u8fd0\u7b97\u7b26\uff09\uff0c\u4e5f\u4e0d\u662f\u6570\u5b57\uff0c\u5219\u5fc5\u987b\u52a0\u4e0a\u5f15\u53f7\uff0c\u5426\u5219\u4f1a\u62a5\u9519<\/p>\n<h3>\u8bfb\u53d6\u5c5e\u6027<\/h3>\n<pre><code class=\"language-javascript\">obj.name || obj[&#039;name&#039;]<\/code><\/pre>\n<p>\u6ce8\u610f: \u6570\u503c\u952e\u540d\u4e0d\u80fd\u4f7f\u7528\u70b9\u8fd0\u7b97\u7b26\uff08\u56e0\u4e3a\u4f1a\u88ab\u5f53\u6210\u5c0f\u6570\u70b9\uff09\uff0c\u53ea\u80fd\u4f7f\u7528\u65b9\u62ec\u53f7\u8fd0\u7b97\u7b26\u3002<\/p>\n<h3>\u68c0\u67e5\u53d8\u91cf\u662f\u5426\u58f0\u660e<\/h3>\n<pre><code class=\"language-javascript\">if(obj.name) || if(obj[&#039;name&#039;])<\/code><\/pre>\n<h3><code>in<\/code>\u8fd0\u7b97\u7b26<\/h3>\n<p>\u7528\u4e8e\u68c0\u67e5\u5bf9\u8c61\u662f\u5426\u5305\u542b\u67d0\u4e2a\u5c5e\u6027\uff0c\u5982\u679c\u5305\u542b\u8fd4\u56detrue\uff0c\u5426\u5219\u8fd4\u56defalse<\/p>\n<pre><code class=\"language-javascript\">if (&#039;x&#039; in obj) {return 1}<\/code><\/pre>\n<h3><code>for \u2026 in<\/code> \u5faa\u73af<\/h3>\n<p>\u7528\u6765\u904d\u5386\u4e00\u4e2a\u5bf9\u8c61\u7684\u5168\u90e8\u5c5e\u6027<\/p>\n<pre><code class=\"language-javascript\">for (var i in obj) {\n  console.log(obj)\n}<\/code><\/pre>\n<h3><code>with<\/code>\u8bed\u53e5<\/h3>\n<p>\u4f5c\u7528: \u64cd\u4f5c\u540c\u4e00\u4e2a\u5bf9\u8c61\u7684\u591a\u4e2a\u5c5e\u6027\u65f6\uff0c\u63d0\u4f9b\u4e00\u4e9b\u4e66\u5199\u7684\u65b9\u4fbf<\/p>\n<pre><code class=\"language-javascript\">with(obj) {\n  name1 = 1\n  name2 = 2\n}<\/code><\/pre>\n<p>\u7b49\u540c\u4e8e<\/p>\n<pre><code class=\"language-javascript\">obj.name1 = 1\nobj.name2 = 2<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u53c2\u6570\u4f20\u503c\u7684\u65b9\u6cd5 data-id \u53ef\u4ee5\u7ed9HTML\u5143\u7d20\u6dfb\u52a0data-*\u5c5e\u6027\u6765\u4f20\u9012\u6211\u4eec\u9700\u8981\u7684\u503c \uff081\uff09\u8bbe\u7f6edata- [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"class_list":["post-1529","post","type-post","status-publish","format-standard","hentry","category-wechat-mini-program"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1529"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1529\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}