{"id":32191,"date":"2024-11-25T12:37:56","date_gmt":"2024-11-25T04:37:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/32191\/"},"modified":"2024-11-25T12:37:56","modified_gmt":"2024-11-25T04:37:56","slug":"vue%e9%a1%b9%e7%9b%ae%e5%92%8c%e5%be%ae%e4%bf%a1%e5%b0%8f%e7%a8%8b%e5%ba%8f%e4%b9%8b%e9%97%b4%e6%9c%89%e4%bd%95%e5%bc%82%e5%90%8c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/32191\/","title":{"rendered":"vue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f"},"content":{"rendered":"<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8evue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<h4>\u524d\u8a00<\/h4>\n<p>\u5199\u4e86vue\u9879\u76ee\u548c\u5c0f\u7a0b\u5e8f\uff0c\u53d1\u73b0\u4e8c\u8005\u6709\u8bb8\u591a\u76f8\u540c\u4e4b\u5904\uff0c\u5728\u6b64\u60f3\u603b\u7ed3\u4e00\u4e0b\u4e8c\u8005\u7684\u5171\u540c\u70b9\u548c\u533a\u522b\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5c0f\u7a0b\u5e8f\u7684\u94a9\u5b50\u51fd\u6570\u8981\u7b80\u5355\u5f97\u591a\u3002<\/p>\n<p>\u5199\u4e86vue\u9879\u76ee\u548c\u5c0f\u7a0b\u5e8f\uff0c\u53d1\u73b0\u4e8c\u8005\u6709\u8bb8\u591a\u76f8\u540c\u4e4b\u5904\uff0c\u5728\u6b64\u60f3\u603b\u7ed3\u4e00\u4e0b\u4e8c\u8005\u7684\u5171\u540c\u70b9\u548c\u533a\u522b\u3002<\/p>\n<p><strong>\u4e00\u3001\u751f\u547d\u5468\u671f<\/strong><\/p>\n<p>\u5148\u8d34\u4e24\u5f20\u56fe\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>vue\u751f\u547d\u5468\u671f<\/p>\n<p><span><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/502\/518\/420\/1533865272390704.png\" class=\"aligncenter\" title=\"vue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\u63d2\u56fe\" alt=\"vue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\u63d2\u56fe\" \/><\/span><\/p>\n<p>\u5c0f\u7a0b\u5e8f\u751f\u547d\u5468\u671f<\/p>\n<p><span><img decoding=\"async\" src=\"https:\/\/img.php.cn\/\/upload\/image\/353\/564\/479\/1533865299105912.png\" class=\"aligncenter\" title=\"vue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\u63d2\u56fe1\" alt=\"vue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\u63d2\u56fe1\" \/><\/span><\/p>\n<p>\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5c0f\u7a0b\u5e8f\u7684\u94a9\u5b50\u51fd\u6570\u8981\u7b80\u5355\u5f97\u591a\u3002<\/p>\n<p>vue\u7684\u94a9\u5b50\u51fd\u6570\u5728\u8df3\u8f6c\u65b0\u9875\u9762\u65f6\uff0c\u94a9\u5b50\u51fd\u6570\u90fd\u4f1a\u89e6\u53d1\uff0c\u4f46\u662f\u5c0f\u7a0b\u5e8f\u7684\u94a9\u5b50\u51fd\u6570\uff0c\u9875\u9762\u4e0d\u540c\u7684\u8df3\u8f6c\u65b9\u5f0f\uff0c\u89e6\u53d1\u7684\u94a9\u5b50\u5e76\u4e0d\u4e00\u6837\u3002<\/p>\n<ul>\n<li>\n<p>onLoad: \u9875\u9762\u52a0\u8f7d<\/p>\n<\/li>\n<\/ul>\n<p>\u4e00\u4e2a\u9875\u9762\u53ea\u4f1a\u8c03\u7528\u4e00\u6b21\uff0c\u53ef\u4ee5\u5728 onLoad \u4e2d\u83b7\u53d6\u6253\u5f00\u5f53\u524d\u9875\u9762\u6240\u8c03\u7528\u7684 query \u53c2\u6570\u3002<\/p>\n<ul>\n<li>\n<p>onShow: \u9875\u9762\u663e\u793a<\/p>\n<\/li>\n<\/ul>\n<p>\u6bcf\u6b21\u6253\u5f00\u9875\u9762\u90fd\u4f1a\u8c03\u7528\u4e00\u6b21\u3002<\/p>\n<ul>\n<li>\n<p>onReady: \u9875\u9762\u521d\u6b21\u6e32\u67d3\u5b8c\u6210<\/p>\n<\/li>\n<\/ul>\n<p>\u4e00\u4e2a\u9875\u9762\u53ea\u4f1a\u8c03\u7528\u4e00\u6b21\uff0c\u4ee3\u8868\u9875\u9762\u5df2\u7ecf\u51c6\u5907\u59a5\u5f53\uff0c\u53ef\u4ee5\u548c\u89c6\u56fe\u5c42\u8fdb\u884c\u4ea4\u4e92\u3002<\/p>\n<p>\u5bf9\u754c\u9762\u7684\u8bbe\u7f6e\u5982wx.setNavigationBarTitle\u8bf7\u5728onReady\u4e4b\u540e\u8bbe\u7f6e\u3002\u8be6\u89c1\u751f\u547d\u5468\u671f<\/p>\n<ul>\n<li>\n<p>onHide: \u9875\u9762\u9690\u85cf<\/p>\n<\/li>\n<\/ul>\n<p>\u5f53navigateTo\u6216\u5e95\u90e8tab\u5207\u6362\u65f6\u8c03\u7528\u3002<\/p>\n<ul>\n<li>\n<p>onUnload: \u9875\u9762\u5378\u8f7d<\/p>\n<\/li>\n<\/ul>\n<p>\u5f53redirectTo\u6216navigateBack\u7684\u65f6\u5019\u8c03\u7528\u3002<\/p>\n<p>\u6570\u636e\u8bf7\u6c42<\/p>\n<p>\u5728\u9875\u9762\u52a0\u8f7d\u8bf7\u6c42\u6570\u636e\u65f6\uff0c\u4e24\u8005\u94a9\u5b50\u7684\u4f7f\u7528\u6709\u4e9b\u7c7b\u4f3c\uff0cvue\u4e00\u822c\u4f1a\u5728created\u6216\u8005mounted\u4e2d\u8bf7\u6c42\u6570\u636e\uff0c\u800c\u5728\u5c0f\u7a0b\u5e8f\uff0c\u4f1a\u5728onLoad\u6216\u8005onShow\u4e2d\u8bf7\u6c42\u6570\u636e\u3002<\/p>\n<p><strong>\u4e8c\u3001\u6570\u636e\u7ed1\u5b9a<\/strong><\/p>\n<p>VUE:vue\u52a8\u6001\u7ed1\u5b9a\u4e00\u4e2a\u53d8\u91cf\u7684\u503c\u4e3a\u5143\u7d20\u7684\u67d0\u4e2a\u5c5e\u6027\u7684\u65f6\u5019\uff0c\u4f1a\u5728\u53d8\u91cf\u524d\u9762\u52a0\u4e0a\u5192\u53f7\uff1a\uff0c\u4f8b\uff1a<\/p>\n<pre>1.  &lt;img  :src=\"imgSrc\"\/ alt=\"vue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\" &gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c0f\u7a0b\u5e8f\uff1a\u7ed1\u5b9a\u67d0\u4e2a\u53d8\u91cf\u7684\u503c\u4e3a\u5143\u7d20\u5c5e\u6027\u65f6\uff0c\u4f1a\u7528\u4e24\u4e2a\u5927\u62ec\u53f7\u62ec\u8d77\u6765\uff0c\u5982\u679c\u4e0d\u52a0\u62ec\u53f7\uff0c\u4e3a\u88ab\u8ba4\u4e3a\u662f\u5b57\u7b26\u4e32\u3002\u4f8b\uff1a<\/p>\n<pre>1.  &lt;image src=\"{{imgSrc}}\"&gt;&lt;\/image&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4e09\u3001\u5217\u8868\u6e32\u67d3<\/strong><\/p>\n<p>\u76f4\u63a5\u8d34\u4ee3\u7801\uff0c\u4e24\u8005\u8fd8\u662f\u6709\u4e9b\u76f8\u4f3c<\/p>\n<p><strong>vue\uff1a<\/strong><\/p>\n<pre>1.  &lt;ul id=\"example-1\"&gt;  \n2.  &lt;li v-for=\"item in items\"&gt;  \n3.  {{ item.message }}  \n4.  &lt;\/li&gt;  \n5.  &lt;\/ul&gt;  \n\n7.  var example1 = new Vue({  \n8.  el: '#example-1',  \n9.  data: {  \n10.  items: [  \n11.  { message: 'Foo' },  \n12.  { message: 'Bar' }  \n13.  ] \n14.  }  \n15.  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5c0f\u7a0b\u5e8f\uff1a<\/strong><\/p>\n<pre>1.  Page({  \n2.  data: {  \n3.  items: [  \n4.  { message: 'Foo' },  \n5.  { message: 'Bar' }  \n6.  ]  \n7.  }  \n8.  })  \n\n10.  &lt;text wx:for=\"{{items}}\"&gt;{{item}}&lt;\/text&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u56db\u3001\u663e\u793a\u4e0e\u9690\u85cf\u5143\u7d20<\/strong><\/p>\n<p>vue\u4e2d\uff0c\u4f7f\u7528v-if \u548cv-show\u63a7\u5236\u5143\u7d20\u7684\u663e\u793a\u548c\u9690\u85cf<\/p>\n<p>\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u4f7f\u7528wx-if\u548chidden\u63a7\u5236\u5143\u7d20\u7684\u663e\u793a\u548c\u9690\u85cf<\/p>\n<p><strong>\u4e94\u3001\u4e8b\u4ef6\u5904\u7406<\/strong><\/p>\n<p>vue\uff1a\u4f7f\u7528v-on:event\u7ed1\u5b9a\u4e8b\u4ef6\uff0c\u6216\u8005\u4f7f\u7528@event\u7ed1\u5b9a\u4e8b\u4ef6,\u4f8b\u5982:<\/p>\n<pre>1.  &lt;button v-on:click=\"counter += 1\"&gt;Add 1&lt;\/button&gt;  \n2.  &lt;button v-on:click.stop=\"counter+=1\"&gt;Add1&lt;\/button&gt;  \/\/\u963b\u6b62\u4e8b\u4ef6\u5192\u6ce1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5168\u7528bindtap(bind+event)\uff0c\u6216\u8005catchtap(catch+event)\u7ed1\u5b9a\u4e8b\u4ef6,\u4f8b\u5982\uff1a<\/p>\n<pre>1.  &lt;button bindtap=\"noWork\"&gt;\u660e\u5929\u4e0d\u4e0a\u73ed&lt;\/button&gt;  \n2.  &lt;button catchtap=\"noWork\"&gt;\u660e\u5929\u4e0d\u4e0a\u73ed&lt;\/button&gt;  \/\/\u963b\u6b62\u4e8b\u4ef6\u5192\u6ce1<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u516d\u3001\u6570\u636e\u53cc\u5411\u7ed1\u5b9a<\/strong><\/p>\n<p><strong>1.\u8bbe\u7f6e\u503c<\/strong><\/p>\n<p>\u5728vue\u4e2d,\u53ea\u9700\u8981\u518d\u8868\u5355\u5143\u7d20\u4e0a\u52a0\u4e0av-model,\u7136\u540e\u518d\u7ed1\u5b9adata\u4e2d\u5bf9\u5e94\u7684\u4e00\u4e2a\u503c\uff0c\u5f53\u8868\u5355\u5143\u7d20\u5185\u5bb9\u53d1\u751f\u53d8\u5316\u65f6\uff0cdata\u4e2d\u5bf9\u5e94\u7684\u503c\u4e5f\u4f1a\u76f8\u5e94\u6539\u53d8\uff0c\u8fd9\u662fvue\u975e\u5e38nice\u7684\u4e00\u70b9\u3002<\/p>\n<pre>1.  &lt;p id=\"app\"&gt;  \n2.  &lt;input v-model=\"reason\" placeholder=\"\u586b\u5199\u7406\u7531\" class='reason'\/&gt;  \n3.  &lt;\/p&gt;  \n\n5.  new Vue({  \n6.  el: '#app',  \n7.  data: {  \n8.  reason:''  \n9.  }  \n10.  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f46\u662f\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u5374\u6ca1\u6709\u8fd9\u4e2a\u529f\u80fd\u3002\u90a3\u600e\u4e48\u529e\u5462\uff1f<\/p>\n<p>\u5f53\u8868\u5355\u5185\u5bb9\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u4f1a\u89e6\u53d1\u8868\u5355\u5143\u7d20\u4e0a\u7ed1\u5b9a\u7684\u65b9\u6cd5\uff0c\u7136\u540e\u5728\u8be5\u65b9\u6cd5\u4e2d\uff0c\u901a\u8fc7this.setData({key:value})\u6765\u5c06\u8868\u5355\u4e0a\u7684\u503c\u8d4b\u503c\u7ed9data\u4e2d\u7684\u5bf9\u5e94\u503c\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4ee3\u7801\uff0c\u53ef\u4ee5\u611f\u53d7\u4e00\u4e0b:<\/p>\n<pre>1.  &lt;input bindinput=\"bindReason\" placeholder=\"\u586b\u5199\u7406\u7531\" class='reason' value='{{reason}}' name=\"reason\" \/&gt;  \n2.  Page({  \n3.  data:{  \n4.  reason:''  \n5.  },  \n6.  bindReason(e) {  \n7.  this.setData({  \n8.  reason: e.detail.value  \n9.  })  \n10.  }  \n11.  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5f53\u9875\u9762\u8868\u5355\u5143\u7d20\u5f88\u591a\u7684\u65f6\u5019\uff0c\u66f4\u6539\u503c\u5c31\u662f\u4e00\u4ef6\u4f53\u529b\u6d3b\u4e86\u3002\u548c\u5c0f\u7a0b\u5e8f\u4e00\u6bd4\u8f83\uff0cvue\u7684v-model\u7b80\u76f4\u723d\u7684\u4e0d\u8981\u4e0d\u8981\u7684\u3002<\/p>\n<p><strong>2.\u53d6\u503c<\/strong><\/p>\n<p>vue\u4e2d\uff0c\u901a\u8fc7this.reason\u53d6\u503c<\/p>\n<p>\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u901a\u8fc7this.data.reason\u53d6\u503c<\/p>\n<p><strong>\u4e03\u3001\u7ed1\u5b9a\u4e8b\u4ef6\u4f20\u53c2<\/strong><\/p>\n<p>\u5728vue\u4e2d\uff0c\u7ed1\u5b9a\u4e8b\u4ef6\u4f20\u53c2\u633a\u7b80\u5355\uff0c\u53ea\u9700\u8981\u5728\u89e6\u53d1\u4e8b\u4ef6\u7684\u65b9\u6cd5\u4e2d\uff0c\u628a\u9700\u8981\u4f20\u9012\u7684\u6570\u636e\u4f5c\u4e3a\u5f62\u53c2\u4f20\u5165\u5c31\u53ef\u4ee5\u4e86\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>1.  &lt;button @click=\"say('\u660e\u5929\u4e0d\u4e0a\u73ed')\"&gt;&lt;\/button&gt;  \n2.  new Vue({  \n3.  el: '#app',  \n4.  methods:{  \n5.  say(arg){  \n6.  consloe.log(arg)  \n7.  }  \n8.  }  \n9.  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u4e0d\u80fd\u76f4\u63a5\u5728\u7ed1\u5b9a\u4e8b\u4ef6\u7684\u65b9\u6cd5\u4e2d\u4f20\u5165\u53c2\u6570\uff0c\u9700\u8981\u5c06\u53c2\u6570\u4f5c\u4e3a\u5c5e\u6027\u503c\uff0c\u7ed1\u5b9a\u5230\u5143\u7d20\u4e0a\u7684data-\u5c5e\u6027\u4e0a\uff0c\u7136\u540e\u5728\u65b9\u6cd5\u4e2d\uff0c\u901a\u8fc7e.currentTarget.dataset.*\u7684\u65b9\u5f0f\u83b7\u53d6\uff0c\u4ece\u800c\u5b8c\u6210\u53c2\u6570\u7684\u4f20\u9012\uff0c\u5f88\u9ebb\u70e6\u6709\u6ca1\u6709&#8230;<\/p>\n<pre>1.  &lt;view class='tr' bindtap='toApprove' data-id=\"{{item.id}}\"&gt;&lt;\/view&gt;  \n2.  Page({  \n3.  data:{  \n4.  reason:''  \n5.  },  \n6.  toApprove(e) {  \n7.  let id = e.currentTarget.dataset.id;  \n8.  }  \n9.  })<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u516b\u3001\u7236\u5b50\u7ec4\u4ef6\u901a\u4fe1<\/strong><\/p>\n<p><strong>1.\u5b50\u7ec4\u4ef6\u7684\u4f7f\u7528<\/strong><\/p>\n<p>\u5728vue\u4e2d\uff0c\u9700\u8981\uff1a<\/p>\n<ol>\n<li>\n<p>\u7f16\u5199\u5b50\u7ec4\u4ef6<\/p>\n<\/li>\n<li>\n<p>\u5728\u9700\u8981\u4f7f\u7528\u7684\u7236\u7ec4\u4ef6\u4e2d\u901a\u8fc7import\u5f15\u5165<\/p>\n<\/li>\n<li>\n<p>\u5728vue\u7684components\u4e2d\u6ce8\u518c<\/p>\n<\/li>\n<li>\n<p>\u5728\u6a21\u677f\u4e2d\u4f7f\u7528&nbsp;<\/p>\n<\/li>\n<\/ol>\n<pre>1.  \/\/\u5b50\u7ec4\u4ef6 bar.vue  \n2.  &lt;template&gt;  \n3.  &lt;p class=\"search-box\"&gt;  \n4.  &lt;p @click=\"say\" :title=\"title\" class=\"icon-dismiss\"&gt;&lt;\/p&gt;  \n5.  &lt;\/p&gt;  \n6.  &lt;\/template&gt;  \n7.  &lt;script&gt;  \n8.  export default{  \n9.  props:{  \n10.  title:{  \n11.  type:String,  \n12.  default:''  \n13.  }  \n14.  }  \n15.  }, \n\n17.  methods:{  \n18.  say(){ \n19.  console.log('\u660e\u5929\u4e0d\u4e0a\u73ed');  \n20.  this.$emit('helloWorld')  \n21.  }  \n22.  } \n23.  &lt;\/script&gt;  \n\n25.  \/\/ \u7236\u7ec4\u4ef6 foo.vue  \n26.  &lt;template&gt;  \n27.  &lt;p class=\"container\"&gt;  \n28.  &lt;bar :title=\"title\" @helloWorld=\"helloWorld\"&gt;&lt;\/bar&gt;  \n29.  &lt;\/p&gt;  \n30.  &lt;\/template&gt;  \n\n32.  &lt;script&gt;  \n33.  import Bar from '.\/bar.vue'  \n34.  export default{  \n35.  data:{  \n36.  title:\"\u6211\u662f\u6807\u9898\"  \n37.  },  \n38.  methods:{  \n39.  helloWorld(){  \n40.  console.log('\u6211\u63a5\u6536\u5230\u5b50\u7ec4\u4ef6\u4f20\u9012\u7684\u4e8b\u4ef6\u4e86')  \n41.  }  \n42.  },  \n43.  components:{ \n44.  Bar  \n45.  }  \n46.  &lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u5c0f\u7a0b\u5e8f\u4e2d\uff0c\u9700\u8981\uff1a<\/p>\n<p>&nbsp; 1.\u7f16\u5199\u5b50\u7ec4\u4ef6<\/p>\n<p>&nbsp; 2. \u5728\u5b50\u7ec4\u4ef6\u7684json\u6587\u4ef6\u4e2d\uff0c\u5c06\u8be5\u6587\u4ef6\u58f0\u660e\u4e3a\u7ec4\u4ef6<\/p>\n<pre>1.  {  \n2.  \"component\": true  \n3.  }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp; 3.\u5728\u9700\u8981\u5f15\u5165\u7684\u7236\u7ec4\u4ef6\u7684json\u6587\u4ef6\u4e2d\uff0c\u5728usingComponents\u586b\u5199\u5f15\u5165\u7ec4\u4ef6\u7684\u7ec4\u4ef6\u540d\u4ee5\u53ca\u8def\u5f84<\/p>\n<pre>1.  \"usingComponents\": {  \n2.  \"tab-bar\": \"..\/..\/components\/tabBar\/tabBar\"  \n3.  }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp; &nbsp;4.\u5728\u7236\u7ec4\u4ef6\u4e2d\uff0c\u76f4\u63a5\u5f15\u5165\u5373\u53ef<\/p>\n<pre>1.  &lt;tab-bar currentpage=\"index\"&gt;&lt;\/tab-bar&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&nbsp; &nbsp; &nbsp; \u5177\u4f53\u4ee3\u7801:<\/p>\n<pre>1.  \/\/ \u5b50\u7ec4\u4ef6  \n2.  &lt;!--components\/tabBar\/tabBar.wxml--&gt;  \n3.  &lt;view class='tabbar-wrapper'&gt;  \n4.  &lt;view class='left-bar {{currentpage===\"index\"?\"active\":\"\"}}' bindtap='jumpToIndex'&gt;  \n5.  &lt;text class='iconfont icon-shouye'&gt;&lt;\/text&gt;  \n6.  &lt;view&gt;\u9996\u9875&lt;\/view&gt;  \n7.  &lt;\/view&gt;  \n8.  &lt;view class='right-bar {{currentpage===\"setting\"?\"active\":\"\"}}' bindtap='jumpToSetting'&gt;  \n9.  &lt;text class='iconfont icon-shezhi'&gt;&lt;\/text&gt;  \n10.  &lt;view&gt;\u8bbe\u7f6e&lt;\/view&gt;  \n11.  &lt;\/view&gt;  \n12.  &lt;\/view&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2.\u7236\u5b50\u7ec4\u4ef6\u95f4\u901a\u4fe1<\/strong><\/p>\n<p><strong>\u5728vue\u4e2d<\/strong><\/p>\n<p>\u7236\u7ec4\u4ef6\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u6570\u636e\uff0c\u53ea\u9700\u8981\u5728\u5b50\u7ec4\u4ef6\u901a\u8fc7v-bind\u4f20\u5165\u4e00\u4e2a\u503c\uff0c\u5728\u5b50\u7ec4\u4ef6\u4e2d\uff0c\u901a\u8fc7props\u63a5\u6536\uff0c\u5373\u53ef\u5b8c\u6210\u6570\u636e\u7684\u4f20\u9012\uff0c\u793a\u4f8b:<\/p>\n<pre>1.  \/\/ \u7236\u7ec4\u4ef6 foo.vue  \n2.  &lt;template&gt;  \n3.  &lt;p class=\"container\"&gt;  \n4.  &lt;bar :title=\"title\"&gt;&lt;\/bar&gt;  \n5.  &lt;\/p&gt;  \n6.  &lt;\/template&gt;  \n7.  &lt;script&gt;  \n8.  import Bar from '.\/bar.vue'  \n9.  export default{  \n10.  data:{  \n11.  title:\"\u6211\u662f\u6807\u9898\"  \n12.  },  \n13.  components:{  \n14.  Bar  \n15.  }  \n16.  &lt;\/script&gt;  \n\n18.  \/\/ \u5b50\u7ec4\u4ef6bar.vue  \n19.  &lt;template&gt;  \n20.  &lt;p class=\"search-box\"&gt;  \n21.  &lt;p :title=\"title\" &gt;&lt;\/p&gt;  \n22.  &lt;\/p&gt;  \n23.  &lt;\/template&gt;  \n24.  &lt;script&gt;  \n25.  export default{  \n26.  props:{  \n27.  title:{  \n28.  type:String,  \n29.  default:''  \n30.  }  \n31.  }  \n32.  }  \n33.  &lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b50\u7ec4\u4ef6\u548c\u7236\u7ec4\u4ef6\u901a\u4fe1\u53ef\u4ee5\u901a\u8fc7this.$emit\u5c06\u65b9\u6cd5\u548c\u6570\u636e\u4f20\u9012\u7ed9\u7236\u7ec4\u4ef6\u3002<\/p>\n<p><strong>\u5728\u5c0f\u7a0b\u5e8f\u4e2d<\/strong><\/p>\n<p>\u7236\u7ec4\u4ef6\u5411\u5b50\u7ec4\u4ef6\u901a\u4fe1\u548cvue\u7c7b\u4f3c\uff0c\u4f46\u662f\u5c0f\u7a0b\u5e8f\u6ca1\u6709\u901a\u8fc7v-bind\uff0c\u800c\u662f\u76f4\u63a5\u5c06\u503c\u8d4b\u503c\u7ed9\u4e00\u4e2a\u53d8\u91cf\uff0c\u5982\u4e0b\uff1a<\/p>\n<pre>1.  &lt;tab-bar currentpage=\"index\"&gt;&lt;\/tab-bar&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u5904\uff0c \u201cindex\u201d\u5c31\u662f\u8981\u5411\u5b50\u7ec4\u4ef6\u4f20\u9012\u7684\u503c<\/p>\n<p>\u5728\u5b50\u7ec4\u4ef6properties\u4e2d\uff0c\u63a5\u6536\u4f20\u9012\u7684\u503c<\/p>\n<pre>1.  properties: {  \n2.  \/\/ \u5f39\u7a97\u6807\u9898  \n3.  currentpage: {            \/\/ \u5c5e\u6027\u540d  \n4.  type: String,     \/\/ \u7c7b\u578b\uff08\u5fc5\u586b\uff09\uff0c\u76ee\u524d\u63a5\u53d7\u7684\u7c7b\u578b\u5305\u62ec\uff1aString, Number, Boolean, Object, Array, null\uff08\u8868\u793a\u4efb\u610f\u7c7b\u578b\uff09  \n5.  value: 'index'     \/\/ \u5c5e\u6027\u521d\u59cb\u503c\uff08\u53ef\u9009\uff09\uff0c\u5982\u679c\u672a\u6307\u5b9a\u5219\u4f1a\u6839\u636e\u7c7b\u578b\u9009\u62e9\u4e00\u4e2a \n6.  } \n7.  }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b50\u7ec4\u4ef6\u5411\u7236\u7ec4\u4ef6\u901a\u4fe1\u548cvue\u4e5f\u5f88\u7c7b\u4f3c\uff0c\u4ee3\u7801\u5982\u4e0b:<\/p>\n<pre>1.  \/\/\u5b50\u7ec4\u4ef6\u4e2d  \n2.  methods: {     \n3.  \/\/ \u4f20\u9012\u7ed9\u7236\u7ec4\u4ef6  \n4.  cancelBut: function (e) {  \n5.  var that = this;  \n6.  var myEventDetail = { pickerShow: false, type: 'cancel' } \/\/ detail\u5bf9\u8c61\uff0c\u63d0\u4f9b\u7ed9\u4e8b\u4ef6\u76d1\u542c\u51fd\u6570  \n7.  this.triggerEvent('myevent', myEventDetail) \/\/myevent\u81ea\u5b9a\u4e49\u540d\u79f0\u4e8b\u4ef6\uff0c\u7236\u7ec4\u4ef6\u4e2d\u4f7f\u7528  \n8.  }, \n9.  }  \n10.  \/\/\u7236\u7ec4\u4ef6\u4e2d  \n11.  &lt;bar bind:myevent=\"toggleToast\"&gt;&lt;\/bar&gt;   \n12.  \/\/ \u83b7\u53d6\u5b50\u7ec4\u4ef6\u4fe1\u606f  \n13.  toggleToast(e){  \n14.  console.log(e.detail)  \n15.  }<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u7236\u7ec4\u4ef6\u60f3\u8981\u8c03\u7528\u5b50\u7ec4\u4ef6\u7684\u65b9\u6cd5<\/p>\n<p>vue\u4f1a\u7ed9\u5b50\u7ec4\u4ef6\u6dfb\u52a0\u4e00\u4e2aref\u5c5e\u6027\uff0c\u901a\u8fc7this.$refs.ref\u7684\u503c\u4fbf\u53ef\u4ee5\u83b7\u53d6\u5230\u8be5\u5b50\u7ec4\u4ef6\uff0c\u7136\u540e\u4fbf\u53ef\u4ee5\u8c03\u7528\u5b50\u7ec4\u4ef6\u4e2d\u7684\u4efb\u610f\u65b9\u6cd5\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>1.  \/\/\u5b50\u7ec4\u4ef6  \n2.  &lt;bar ref=\"bar\"&gt;&lt;\/bar&gt;  \n3.  \/\/\u7236\u7ec4\u4ef6  \n4.  this.$ref.bar.\u5b50\u7ec4\u4ef6\u7684\u65b9\u6cd5<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5c0f\u7a0b\u5e8f\u662f\u7ed9\u5b50\u7ec4\u4ef6\u6dfb\u52a0id\u6216\u8005class\uff0c\u7136\u540e\u901a\u8fc7this.selectComponent\u627e\u5230\u5b50\u7ec4\u4ef6\uff0c\u7136\u540e\u518d\u8c03\u7528\u5b50\u7ec4\u4ef6\u7684\u65b9\u6cd5,\u793a\u4f8b\uff1a<\/p>\n<pre>1.  \/\/\u5b50\u7ec4\u4ef6  \n2.  &lt;bar id=\"bar\"&gt;&lt;\/bar&gt;  \n3.  \/\/ \u7236\u7ec4\u4ef6  \n4.  this.selectComponent('#id').syaHello()<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fvue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\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>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5e26\u6765\u7684\u5185\u5bb9\u662f\u5173\u4e8evue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f\uff0c\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u6709\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\u3002 \u524d\u8a00 \u5199\u4e86vue\u9879\u76ee\u548c\u5c0f\u7a0b\u5e8f\uff0c\u53d1\u73b0\u4e8c\u8005\u6709\u8bb8\u591a\u76f8\u540c\u4e4b\u5904\uff0c\u5728\u6b64\u60f3\u603b\u7ed3\u4e00\u4e0b\u4e8c\u8005\u7684\u5171\u540c\u70b9\u548c\u533a\u522b\u3002\u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5c0f\u7a0b\u5e8f\u7684\u94a9\u5b50\u51fd\u6570\u8981\u7b80\u5355\u5f97\u591a\u3002 \u5199\u4e86vue\u9879\u76ee\u548c\u5c0f\u7a0b\u5e8f\uff0c\u53d1\u73b0\u4e8c\u8005\u6709\u8bb8\u591a\u76f8\u540c\u4e4b\u5904\uff0c\u5728\u6b64\u60f3\u603b\u7ed3\u4e00\u4e0b\u4e8c\u8005\u7684\u5171\u540c\u70b9\u548c\u533a\u522b\u3002 \u4e00\u3001\u751f\u547d\u5468\u671f \u5148\u8d34\u4e24\u5f20\u56fe\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b vue\u751f\u547d\u5468\u671f \u5c0f\u7a0b\u5e8f\u751f\u547d\u5468\u671f \u76f8\u6bd4\u4e4b\u4e0b\uff0c\u5c0f\u7a0b\u5e8f\u7684\u94a9\u5b50\u51fd\u6570\u8981\u7b80\u5355\u5f97\u591a\u3002 vue\u7684\u94a9\u5b50\u51fd\u6570\u5728\u8df3\u8f6c\u65b0\u9875\u9762\u65f6\uff0c\u94a9\u5b50\u51fd\u6570\u90fd\u4f1a\u89e6\u53d1\uff0c\u4f46\u662f\u5c0f\u7a0b\u5e8f\u7684\u94a9\u5b50\u51fd\u6570\uff0c\u9875\u9762\u4e0d\u540c\u7684\u8df3\u8f6c\u65b9\u5f0f\uff0c\u89e6\u53d1\u7684\u94a9\u5b50\u5e76\u4e0d\u4e00\u6837\u3002 onLoad: \u9875\u9762\u52a0\u8f7d \u4e00\u4e2a\u9875\u9762\u53ea\u4f1a\u8c03\u7528\u4e00\u6b21\uff0c\u53ef\u4ee5\u5728 onLoad \u4e2d\u83b7\u53d6\u6253\u5f00\u5f53\u524d\u9875\u9762\u6240\u8c03\u7528\u7684 query \u53c2\u6570\u3002 onShow: \u9875\u9762\u663e\u793a \u6bcf\u6b21\u6253\u5f00\u9875\u9762\u90fd\u4f1a\u8c03\u7528\u4e00\u6b21\u3002 onReady: \u9875\u9762\u521d\u6b21\u6e32\u67d3\u5b8c\u6210 \u4e00\u4e2a\u9875\u9762\u53ea\u4f1a\u8c03\u7528\u4e00\u6b21\uff0c\u4ee3\u8868\u9875\u9762\u5df2\u7ecf\u51c6\u5907\u59a5\u5f53\uff0c\u53ef\u4ee5\u548c\u89c6\u56fe\u5c42\u8fdb\u884c\u4ea4\u4e92\u3002 \u5bf9\u754c\u9762\u7684\u8bbe\u7f6e\u5982wx.setNavigationBarTitle\u8bf7\u5728onReady\u4e4b\u540e\u8bbe\u7f6e\u3002\u8be6\u89c1\u751f\u547d\u5468\u671f onHide: \u9875\u9762\u9690\u85cf \u5f53navigateTo\u6216\u5e95\u90e8tab\u5207\u6362\u65f6\u8c03\u7528\u3002 onUnload: \u9875\u9762\u5378\u8f7d \u5f53redirectTo\u6216navigateBack\u7684\u65f6\u5019\u8c03\u7528\u3002 \u6570\u636e\u8bf7\u6c42 \u5728\u9875\u9762\u52a0\u8f7d\u8bf7\u6c42\u6570\u636e\u65f6\uff0c\u4e24\u8005\u94a9\u5b50\u7684\u4f7f\u7528\u6709\u4e9b\u7c7b\u4f3c\uff0cvue\u4e00\u822c\u4f1a\u5728created\u6216\u8005mounted\u4e2d\u8bf7\u6c42\u6570\u636e\uff0c\u800c\u5728\u5c0f\u7a0b\u5e8f\uff0c\u4f1a\u5728onLoad\u6216\u8005onShow\u4e2d\u8bf7\u6c42\u6570\u636e\u3002 \u4e8c\u3001\u6570\u636e\u7ed1\u5b9a VUE:vue\u52a8\u6001\u7ed1\u5b9a\u4e00\u4e2a\u53d8\u91cf\u7684\u503c\u4e3a\u5143\u7d20\u7684\u67d0\u4e2a\u5c5e\u6027\u7684\u65f6\u5019\uff0c\u4f1a\u5728\u53d8\u91cf\u524d\u9762\u52a0\u4e0a\u5192\u53f7\uff1a\uff0c\u4f8b\uff1a 1. &lt;img :src=&#8221;imgSrc&#8221;\/ alt=&#8221;vue\u9879\u76ee\u548c\u5fae\u4fe1\u5c0f\u7a0b\u5e8f\u4e4b\u95f4\u6709\u4f55\u5f02\u540c\uff1f&#8221; &gt; \u767b\u5f55\u540e\u590d\u5236 \u5c0f\u7a0b\u5e8f\uff1a\u7ed1\u5b9a\u67d0\u4e2a\u53d8\u91cf\u7684\u503c\u4e3a\u5143\u7d20\u5c5e\u6027\u65f6\uff0c\u4f1a\u7528\u4e24\u4e2a\u5927\u62ec\u53f7\u62ec\u8d77\u6765\uff0c\u5982\u679c\u4e0d\u52a0\u62ec\u53f7\uff0c\u4e3a\u88ab\u8ba4\u4e3a\u662f\u5b57\u7b26\u4e32\u3002\u4f8b\uff1a 1. &lt;image src=&#8221;{{imgSrc}}&#8221;&gt;&lt;\/image&gt; \u767b\u5f55\u540e\u590d\u5236 \u4e09\u3001\u5217\u8868\u6e32\u67d3 \u76f4\u63a5\u8d34\u4ee3\u7801\uff0c\u4e24\u8005\u8fd8\u662f\u6709\u4e9b\u76f8\u4f3c vue\uff1a 1. &lt;ul id=&#8221;example-1&#8243;&gt; 2. &lt;li v-for=&#8221;item [&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-32191","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32191","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=32191"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/32191\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=32191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=32191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=32191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}