{"id":1516,"date":"2023-03-25T14:09:47","date_gmt":"2023-03-25T06:09:47","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1516"},"modified":"2023-04-28T20:20:15","modified_gmt":"2023-04-28T12:20:15","slug":"wechat-mini-program-implements-shared-filter-through-wxs","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/25\/wechat-mini-program-implements-shared-filter-through-wxs\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u901a\u8fc7WXS\u5b9e\u73b0\u5171\u4eabfilter\u8fc7\u6ee4\u5668"},"content":{"rendered":"<p>WXS\uff08WeiXin Script\uff09\u662f\u5c0f\u7a0b\u5e8f\u7684\u4e00\u5957\u811a\u672c\u8bed\u8a00\uff0c\u7ed3\u5408 WXML\uff0c\u53ef\u4ee5\u6784\u5efa\u51fa\u9875\u9762\u7684\u7ed3\u6784\u3002WXS \u76ee\u524d\u4e3b\u8981\u662f\u589e\u5f3a WXML \u6807\u7b7e\u7684\u8868\u8fbe\u80fd\u529b\u3002<\/p>\n<p>\u5b98\u65b9\u6587\u6863\uff1a<a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/framework\/view\/wxs\/\">https:\/\/mp.weixin.qq.com\/debug\/wxadoc\/dev\/framework\/view\/wxs\/<\/a><\/p>\n<p><!-- more --><\/p>\n<p>1\u3001\u9996\u5148\u6211\u4eec\u5efa\u7acb\u5171\u4eabfilter\u6587\u4ef6\u5939\uff0c\u5b9e\u73b0\u4e00\u4e2a\u65e5\u671f\u683c\u5f0f\u5316<\/p>\n<p>WXS \u5b9e\u73b0\u65e5\u671f\u683c\u5f0f\u5316\uff08es6\u8bed\u6cd5\u4e0d\u80fd\u4f7f\u7528)<\/p>\n<pre><code class=\"language-javascript\">var DateFormat = {\n  getDate: function (time, splitStr) {\n\n  if (!time) return &#039;&#039;;\n\n  var date =getDate(time);\n  var M = date.getMonth() + 1;\n  var y = date.getFullYear();\n  var d = date.getDate();\n\n  if (M &lt; 10) M = &quot;0&quot; + M;\n  if (d &lt; 10) d = &quot;0&quot; + d;\n\n  if (splitStr)\n    return y +splitStr + M + splitStr+d;\n  else\n    return {\n      y: y,\n      M: M,\n      d: d\n    };\n  }\n}\n\nmodule.exports = {\n  getDate: DateFormat.getDate\n}<\/code><\/pre>\n<p>2\u3001\u5728\u4e1a\u52a1\u9875\u9762wxml\u4e2d\u4f7f\u7528wxs<\/p>\n<pre><code>&lt;wxs module=&quot;dateFormat&quot; src=&quot;..\/..\/filter\/DateFormat.wxs&quot;&gt;&lt;\/wxs&gt;<\/code><\/pre>\n<p>\u4f7f\u7528filter<\/p>\n<pre><code>&lt;text &gt;{{dateFormat.getTime(item.createdAt, &#039;:&#039;)}}&lt;\/text&gt;<\/code><\/pre>\n<blockquote>\n<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u7684\u67b6\u6784\u5206\u4e3a app-service \u548c page-frame\uff0c\u5206\u522b\u8fd0\u884c\u4e8e\u4e0d\u540c\u7684\u7ebf\u7a0b\u3002\u4f60\u5728\u5f00\u53d1\u65f6\u5199\u7684\u6240\u6709 JS \u90fd\u662f\u8fd0\u884c\u5728 app-service \u7ebf\u7a0b\u91cc\u7684\uff0c\u800c\u6bcf\u4e2a\u9875\u9762\u5404\u81ea\u7684 WXML\/WXSS \u5219\u8fd0\u884c\u5728 page-frame \u4e2d\u3002app-service \u4e0e page-frame \u4e4b\u95f4\u901a\u8fc7\u6865\u534f\u8bae\u901a\u4fe1\uff08\u5305\u62ec setData \u8c03\u7528\u3001canvas\u6307\u4ee4\u548c\u5404\u79cdDOM\u4e8b\u4ef6\uff09\uff0c\u6d89\u53ca\u6d88\u606f\u5e8f\u5217\u5316\u3001\u8de8\u7ebf\u7a0b\u901a\u4fe1\u4e0eevaluateJavascript()\u3002\u8fd9\u4e2a\u67b6\u6784\u7684\u597d\u5904\u662f\uff1a\u5206\u5f00\u4e86\u4e1a\u52a1\u4e3b\u7ebf\u7a0b\u548c\u663e\u793a\u754c\u9762\uff0c\u5373\u4fbf\u4e1a\u52a1\u4e3b\u7ebf\u7a0b\u975e\u5e38\u7e41\u5fd9\uff0c\u4e5f\u4e0d\u4f1a\u963b\u585e\u7528\u6237\u5728 page-frame \u4e0a\u7684\u4ea4\u4e92\u3002\u4e00\u4e2a\u5c0f\u7a0b\u5e8f\u53ef\u4ee5\u6709\u591a\u4e2a page-frame \uff08webview\uff09\uff0c\u9875\u9762\u95f4\u5207\u6362\u52a8\u753b\u6bd4SPA\u66f4\u6d41\u7545\u3002\u574f\u5904\u662f\uff1a\u5728 page-frame \u4e0a\u65e0\u6cd5\u8c03\u7528\u4e1a\u52a1 JS\u3002\u8de8\u7ebf\u7a0b\u901a\u4fe1\u7684\u6210\u672c\u5f88\u9ad8\uff0c\u4e0d\u9002\u5408\u9700\u8981\u9891\u7e41\u901a\u4fe1\u7684\u573a\u666f\u3002\u4e1a\u52a1 JS \u65e0\u6cd5\u76f4\u63a5\u63a7\u5236 DOM\u3002<\/p>\n<p>\u56e0\u4e3a\u8fd0\u884c\u5728\u4e0d\u540c\u7ebf\u7a0b\u6240\u4ee5 js\u4e0ewxs \u4e0d\u80fd\u76f8\u4e92\u5f15\u7528\u7684\u3002\u8fd9\u5c31\u6709\u53ef\u80fd\u5728js\u4e2d\u4f7f\u7528\u7684\u516c\u5171\u65b9\u6cd5\u5728wxs\u4e2d\u9700\u8981\u91cd\u65b0\u5199\u4e00\u4efd(\u4e3a\u4e86\u5171\u4eabfilter)\uff0c\u9020\u6210\u4ee3\u7801\u5197\u4f59\u3002<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>WXS\uff08WeiXin Script\uff09\u662f\u5c0f\u7a0b\u5e8f\u7684\u4e00\u5957\u811a\u672c\u8bed\u8a00\uff0c\u7ed3\u5408 WXML\uff0c\u53ef\u4ee5\u6784\u5efa\u51fa\u9875\u9762\u7684\u7ed3\u6784\u3002WXS \u76ee\u524d [&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-1516","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\/1516","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=1516"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1516\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}