{"id":32444,"date":"2024-11-25T16:32:48","date_gmt":"2024-11-25T08:32:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32444\/"},"modified":"2024-11-25T16:32:48","modified_gmt":"2024-11-25T08:32:48","slug":"%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b8%ad%e9%80%89%e9%a1%b9%e5%8d%a1%e7%9a%84%e5%ae%9e%e7%8e%b0%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32444\/","title":{"rendered":"\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u9009\u9879\u5361\u7684\u5b9e\u73b0\u65b9\u6cd5"},"content":{"rendered":"<p>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u9009\u9879\u5361\u7684\u5e94\u7528\u968f\u5904\u53ef\u89c1\uff0c\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u9009\u9879\u5361\u7684\u5b9e\u73b0\u3002<\/p>\n<h2>\u601d\u8def<\/h2>\n<ul>\n<li>\n<p>\u4e4b\u524d\u5199\u8fc7\u57fa\u4e8eswiper\u7684\u9009\u9879\u5361\uff0c\u5728\u5c0f\u7a0b\u5e8f\u4e2d\u6709swiper\u7ec4\u4ef6\uff0c\u6beb\u65e0\u7591\u95ee\u8fd9\u91cc\u8981\u7528\u5230swiper\u7ec4\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u6709\u4e2a\u95ee\u9898\u5c31\u662f\u4e0d\u80fd\u6839\u636e\u5185\u5bb9\u81ea\u9002\u5e94\u9ad8\u5ea6\uff0c\u6240\u4ee5\u8981\u901a\u8fc7wx.getSystemInfoSync\u83b7\u53d6\u8bbe\u5907\u9ad8\u5ea6\u8bbe\u7f6eswiper\u9ad8\u5ea6<\/p>\n<\/li>\n<li>\n<p>\u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u4e2dswiper-item\u5185\u5bb9\u8d85\u51fa\u53ef\u89c6\u533a\u540e\u65e0\u6cd5\u6eda\u52a8\u663e\u793a\uff0c\u6240\u4ee5\u8fd9\u91cc\u8981\u7528\u5230\u53e6\u4e00\u4e2a\u7ec4\u4ef6scroll-view\u3002<\/p>\n<\/li>\n<\/ul>\n<p><em>\u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u529f\u80fd\u8fd8\u662f\u6bd4\u8f83\u6709\u9650\u7684\uff0c\u6709\u5f85\u4f18\u5316\u3002<\/em><\/p>\n<h2>\u65b9\u6848<\/h2>\n<h3>1.\u9996\u5148\u5728js\u4e2d\u8bbe\u7f6e\u6570\u636e<\/h3>\n<pre> data: {\n    tabs: ['\u83dc\u5355\u4e00', '\u83dc\u5355\u4e8c'],\/\/ \u5bfc\u822a\u83dc\u5355\u680f\n    curIdx:0,\/\/ \u5f53\u524d\u5bfc\u822a\u7d22\u5f15\n    scrollHeight:0, \/\/\u6eda\u52a8\u9ad8\u5ea6 = \u8bbe\u5907\u53ef\u89c6\u533a\u9ad8\u5ea6 -  \u5bfc\u822a\u680f\u9ad8\u5ea6\n    list:[],\/\/ \u5185\u5bb9\u533a\u5217\u8868\n  },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728onLoad\u51fd\u6570\u4e2d\u586b\u5145\u6570\u636e<\/p>\n<pre>  \/**\n   * \u751f\u547d\u5468\u671f\u51fd\u6570--\u76d1\u542c\u9875\u9762\u52a0\u8f7d\n   *\/\n  onLoad: function (options) {\n    let list=[];\n    for (let i=1;i&lt;=30;i++){\n      list.push(i)\n    }\n    this.setData({\n      list: list\n    });\n  },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>2.\u5728WXML\u4e2d\u5faa\u73af\u6e32\u67d3\u51fa\u5bfc\u822a<\/h3>\n<pre>&lt;!-- \u5bfc\u822a\u680f\u5f00\u59cb --&gt;\n&lt;view class=\"swiper-tab\"&gt;\n  &lt;view wx:for=\"{{tabs}}\" wx:key class=\"swiper-tab-item {{curIdx==index?'swiper-active':''}}\" data-current=\"{{index}}\" catchtap=\"clickTab\"&gt;\n    &lt;text&gt;{{item}}&lt;\/text&gt;\n  &lt;\/view&gt;\n&lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>3.\u8bbe\u7f6e\u5f53\u524d\u6d3b\u52a8\u5bfc\u822a\u6837\u5f0f<\/h3>\n<pre>\/*\u521d\u59cb\u5316\u6837\u5f0f*\/\nview, text, picker, input, button, image{\n  display: flex;\n  box-sizing: border-box;\n}\n\/* \u5bfc\u822a\u6837\u5f0f*\/\n.swiper-tab {\n  position: relative;\n  width: 100%;\n  height: 100rpx;\n  justify-content: center;\n  align-items: center;\n}\n\n.swiper-tab-item {\n  background-color: #f3f3f3;\n  width: 50%;\n  height: 80rpx;\n  justify-content: center;\n  align-items: center;\n}\n.swiper-active{\n  background-color: rgb(129, 190, 247);\n  color: #fff;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>4.\u5185\u5bb9\u663e\u793a\u533a<\/h3>\n<p>\u5185\u5bb9\u663e\u793a\u533a\u4f7f\u7528swiper\u7ec4\u4ef6\uff0cswiper-item\u4e2a\u6570\u8981\u4e0etabs\u6570\u7ec4\u957f\u5ea6 \u4e00\u81f4<\/p>\n<pre>&lt;!-- \u5185\u5bb9\u5f00\u59cb --&gt;\n&lt;swiper class=\"swiper_content\" current=\"{{curIdx}}\"   bindchange=\"swiperTab\" style='height:{{scrollHeight}}px'&gt;\n  &lt;swiper-item&gt;\n    &lt;scroll-view class=\"scroll-y\" scroll-y style='height:{{scrollHeight}}px' bindscrolltolower=\"onReachBottom\"&gt;\n    &lt;view wx:for=\"{{list}}\" wx:key&gt;\n      &lt;text&gt; \u5185\u5bb9\u4e00{{item}}&lt;\/text&gt;\n    &lt;\/view&gt;\n        &lt;\/scroll-view&gt;\n  &lt;\/swiper-item&gt;\n  &lt;swiper-item&gt;\n    \u5185\u5bb9\u4e8c\n  &lt;\/swiper-item&gt;\n&lt;\/swiper&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u6709\u4e2a\u95ee\u9898\u5c31\u662f\u4e0d\u80fd\u6839\u636e\u5185\u5bb9\u81ea\u9002\u5e94\u9ad8\u5ea6\uff0c\u6240\u4ee5\u8981\u901a\u8fc7[wx.getSystemInfoSync][4]\u83b7\u53d6\u8bbe\u5907\u9ad8\u5ea6\u8bbe\u7f6eswiper\u9ad8\u5ea6<br \/>\u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u4e2dswiper-item\u5185\u5bb9\u8d85\u51fa\u53ef\u89c6\u533a\u540e\u65e0\u6cd5\u6eda\u52a8\u663e\u793a\uff0c\u6240\u4ee5\u8fd9\u91cc\u8981\u7528\u5230\u53e6\u4e00\u4e2a\u7ec4\u4ef6[scroll-view][5]\u3002<br \/>\u6211\u4eec\u5728onShow\u51fd\u6570\u4e2d\u901a\u8fc7getSystemInfoSync\u83b7\u53d6\u8bbe\u5907\u7684\u5bbd\u9ad8\u6765\u8bbe\u7f6eswiper\u7ec4\u4ef6\u9ad8\u5ea6\u4ee5\u53cascroll-view\u9ad8\u5ea6<\/p>\n<pre>  onShow: function () {\n    \/\/ 100\u4e3a\u5bfc\u822a\u680fswiper-tab \u7684\u9ad8\u5ea6\n   this.setData({\n     scrollHeight: wx.getSystemInfoSync().windowHeight - (wx.getSystemInfoSync().windowWidth \/ 750 * 100),\n   })\n  },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>5.\u70b9\u51fb\u5bfc\u822a\u680f\u5207\u6362\u5185\u5bb9<\/h3>\n<pre>  \/\/\u70b9\u51fb\u5207\u6362\n  clickTab: function (e) {\n    this.setData({\n      curIdx: e.currentTarget.dataset.current\n    })\n  },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>6.\u6ed1\u52a8\u5185\u5bb9\u5207\u6362\u5bfc\u822a\u680f<\/h3>\n<pre>  \/\/\u6ed1\u52a8\u5207\u6362\n  swiperTab: function (e) {\n    this.setData({\n      curIdx: e.detail.current\n    });\n  },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>7.\u53ef\u6eda\u52a8\u533a\u57df\u6eda\u52a8\u6700\u5e95\u5237\u65b0\u6570\u636e<\/h3>\n<pre>\n  \/**\n * \u9875\u9762\u4e0a\u62c9\u89e6\u5e95\u4e8b\u4ef6\u7684\u5904\u7406\u51fd\u6570\n *\/\n  onReachBottom: function () {\n    \/\/ \u66f4\u65b0\u5217\u8868\n    let list = this.data.list;\n    console.log(list)\n    let lens = list.length\n    for (let i = lens; i &lt; lens+30; i++) {\n      list.push(i)\n    }\n    this.setData({\n      list: list\n    });\n  \n  },<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e00\u4e2a\u6f02\u4eae\u7684\u9009\u9879\u5361\u5c31\u5b8c\u6210\u4e86\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u7bc7\u6587\u7ae0\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u66f4\u591a\u7cbe\u5f69\u8bf7\u5173\u6ce8\u7c73\u4e91\u3002<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u9009\u9879\u5361\u7684\u5b9e\u73b0\u65b9\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>\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u9009\u9879\u5361\u7684\u5e94\u7528\u968f\u5904\u53ef\u89c1\uff0c\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e2d\u9009\u9879\u5361\u7684\u5b9e\u73b0\u3002 \u601d\u8def \u4e4b\u524d\u5199\u8fc7\u57fa\u4e8eswiper\u7684\u9009\u9879\u5361\uff0c\u5728\u5c0f\u7a0b\u5e8f\u4e2d\u6709swiper\u7ec4\u4ef6\uff0c\u6beb\u65e0\u7591\u95ee\u8fd9\u91cc\u8981\u7528\u5230swiper\u7ec4\u4ef6 \u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u6709\u4e2a\u95ee\u9898\u5c31\u662f\u4e0d\u80fd\u6839\u636e\u5185\u5bb9\u81ea\u9002\u5e94\u9ad8\u5ea6\uff0c\u6240\u4ee5\u8981\u901a\u8fc7wx.getSystemInfoSync\u83b7\u53d6\u8bbe\u5907\u9ad8\u5ea6\u8bbe\u7f6eswiper\u9ad8\u5ea6 \u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u4e2dswiper-item\u5185\u5bb9\u8d85\u51fa\u53ef\u89c6\u533a\u540e\u65e0\u6cd5\u6eda\u52a8\u663e\u793a\uff0c\u6240\u4ee5\u8fd9\u91cc\u8981\u7528\u5230\u53e6\u4e00\u4e2a\u7ec4\u4ef6scroll-view\u3002 \u5c0f\u7a0b\u5e8f\u4e2d\u7684swiper\u7ec4\u4ef6\u529f\u80fd\u8fd8\u662f\u6bd4\u8f83\u6709\u9650\u7684\uff0c\u6709\u5f85\u4f18\u5316\u3002 \u65b9\u6848 1.\u9996\u5148\u5728js\u4e2d\u8bbe\u7f6e\u6570\u636e data: { tabs: [&#8216;\u83dc\u5355\u4e00&#8217;, &#8216;\u83dc\u5355\u4e8c&#8217;],\/\/ \u5bfc\u822a\u83dc\u5355\u680f curIdx:0,\/\/ \u5f53\u524d\u5bfc\u822a\u7d22\u5f15 scrollHeight:0, \/\/\u6eda\u52a8\u9ad8\u5ea6 = \u8bbe\u5907\u53ef\u89c6\u533a\u9ad8\u5ea6 &#8211; \u5bfc\u822a\u680f\u9ad8\u5ea6 list:[],\/\/ \u5185\u5bb9\u533a\u5217\u8868 }, \u767b\u5f55\u540e\u590d\u5236 \u5728onLoad\u51fd\u6570\u4e2d\u586b\u5145\u6570\u636e \/** * \u751f\u547d\u5468\u671f\u51fd\u6570&#8211;\u76d1\u542c\u9875\u9762\u52a0\u8f7d *\/ onLoad: function (options) { let list=[]; for (let i=1;i&lt;=30;i++){ list.push(i) } this.setData({ list: list }); }, \u767b\u5f55\u540e\u590d\u5236 2.\u5728WXML\u4e2d\u5faa\u73af\u6e32\u67d3\u51fa\u5bfc\u822a &lt;!&#8211; \u5bfc\u822a\u680f\u5f00\u59cb &#8211;&gt; &lt;view class=&#8221;swiper-tab&#8221;&gt; &lt;view [&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-32444","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32444","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=32444"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32444\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32444"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32444"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32444"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}