{"id":31144,"date":"2024-11-25T08:08:39","date_gmt":"2024-11-25T00:08:39","guid":{"rendered":"https:\/\/fwq.ai\/blog\/31144\/"},"modified":"2024-11-25T08:08:39","modified_gmt":"2024-11-25T00:08:39","slug":"vue-js-%e4%b9%8b-iview-ui-%e6%a1%86%e6%9e%b6%e9%9d%9e%e5%b7%a5%e7%a8%8b%e5%8c%96%e5%ae%9e%e8%b7%b5%e5%88%86%e4%ba%ab","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/31144\/","title":{"rendered":"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab"},"content":{"rendered":"<p>vue.js \u662f\u7f8e\u7c4d\u534e\u4eba\u5c24\u96e8\u6eaa\u521b\u4f5c\u7684\uff0c\u90a3\u4f1a\u513f\u4ed6\u8fd8\u5728 google \u5de5\u4f5c\uff0c\u4ed6\u81ea\u611f angular.js \u7e41\u6742\uff0c\u8fdb\u800c\u81ea\u521b\u4e86\u66f4\u4e3a\u7b80\u6d01\u6613\u7528\u7684 vue.js\u3002\u672c\u6587\u6211\u4eec\u4e3b\u8981\u548c\u5927\u5bb6\u5206\u4eabvue.js \u4e4b iview ui \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002<\/p>\n<p>iView UI \u662f\u7531 90 \u540e\u6881\u704f[h\u00e0o]\u521b\u4f5c\uff0c\u7f51\u540d Aresn\uff0c\u5728\u5927\u6570\u636e\u516c\u53f8 TalkingData \u8d1f\u8d23\u53ef\u89c6\u5316\u57fa\u7840\u67b6\u6784\uff0c\u66f4\u4e86\u4e0d\u8d77\u7684\u662f\u4ed6\u8fd8\u51fa\u4e86\u300aVue.js\u5b9e\u6218\u300b\u4e00\u4e66\uff0c\u6211\u662f\u5728\u201c\u53cc\u5341\u4e00\u201d\u7684\u524d\u4e00\u5929\u4e70\u7684\uff0c\u884c\u6587\u63aa\u8bcd\u7b80\u6d01\uff0c\u8868\u610f\u76f4\u8fbe\u56f0\u60d1\uff0c\u5165\u95e8\u5f88\u8fc5\u901f\uff0c\u662f\u6211\u559c\u6b22\u7684\u98ce\u683c\u3002\u82b1\u4e86\u4e00\u5468\u65f6\u95f4\u626b\u5b8c\u4e86\u524d\u5341\u4e8c\u7ae0\u5185\u5bb9\uff0c\u7528 WebStorm \u7ec3\u4e60\u4e86\u5927\u90e8\u5206\u5b9e\u4f8b\uff0c\u5c3d\u7ba1\u4e66\u4e2d\u7528\u4e00\u6574\u7ae0\u5185\u5bb9\u4ecb\u7ecd\u4e86 webpack \u5de5\u7a0b\u5316\u6784\u5efa\u65b9\u6848\uff0c\u4f46\u7531\u4e8e\u6211\u60ef\u6027\u4f7f\u7136\uff0c\u8fd8\u662f\u9009\u62e9\u5bf9\u5176\u8df3\u8fc7\u800c\u4f7f\u7528\u4e86\u975e\u5de5\u7a0b\u5316\u65b9\u5f0f\u6765\u4f53\u9a8c Vue.js\uff0c\u5176\u5b9e\u591a\u5c11\u6709\u5931\u66b4\u6b84\u3002\u65e0\u5948\uff0c\u6bd5\u7adf\u624d\u5b66\u4e86\u4e00\u5468\uff0c\u540e\u671f\u65f6\u95f4\u5145\u88d5\u4e86\u518d\u63a5\u7740\u5206\u4eab\u5de5\u7a0b\u5316\u6784\u5efa\u7684\u5b66\u4e60\u5fc3\u5f97\u5427\u3002<\/p>\n<p>\u4e00\u3001 MVVM \u6a21\u5f0f<\/p>\n<p>Vue.js \u6bd4\u8f83\u663e\u8457\u7684\u7279\u5f81\u662f\u89e3\u8026\u4e86\u89c6\u56fe\u548c\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u8bf4\u89c6\u56fe\u7684\u53d8\u5316\u4e0d\u518d\u9700\u8981\u547d\u4ee4\u5f0f\u7f16\u7a0b\u53bb\u663e\u5f0f\u6539\u53d8\uff0c\u53ea\u8981\u4fee\u6539\u5b8c\u6570\u636e\u5c31\u80fd\u7acb\u5373\u81ea\u52a8\u540c\u6b65\uff0c\u8fd9\u662f\u6bd4\u8f83\u5927\u7684\u4e00\u4e2a\u601d\u7ef4\u6a21\u5f0f\u7684\u8f6c\u53d8\uff0c\u53e6\u4e00\u4e2a\u5c31\u662f\u7ec4\u4ef6\u5316\u601d\u7ef4\u4fef\u9996\u7686\u662f\uff0c\u8fd9\u6837\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u5c31\u76f8\u5f53\u662f\u5728\u642d\u79ef\u6728\u3002<\/p>\n<p>\u5176\u5b9e\u4ee5\u4e0a\u5bf9 Vue.js \u6240\u9610\u8ff0\u7684\u4f18\u70b9\u4e5f\u6b63\u662f MVVM \u6a21\u5f0f\u7684\u5199\u7167\uff0c\u5b83\u539f\u662f\u7531 MVC \u6240\u884d\u751f\uff0c\u5373\u5f53\u89c6\u56fe\u5c42\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u4f1a\u81ea\u52a8\u66f4\u65b0\u5230\u89c6\u56fe\u6a21\u578b\u4e0a\uff0c\u53cd\u4e4b\u4ea6\u7136\uff0c\u8fd9\u5c31\u662f\u5e38\u8bf4\u7684\u53cc\u5411\u7ed1\u5b9a\uff0c\u4e0a\u4e00\u5f20\u56fe\u5427\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/06f564735aa12db3b3b3150fbdef5e42-0.jpg\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe\" \/><\/p>\n<p>\u752d\u7ba1\u8fd9\u56fe\u662f\u5426\u597d\u7406\u89e3\uff0c\u901a\u4fd7\u5730\u6765\u8bb2\uff0cMVVM \u8fd9\u79cd\u6a21\u5f0f\u62c6\u5206\u4e86\u89c6\u56fe\u548c\u6570\u636e\uff0c\u8fd9\u6837\u6211\u4eec\u5728\u5f00\u53d1\u65f6\u53ea\u8981\u5173\u5fc3\u6570\u636e\u672c\u8eab\u5373\u53ef\uff0c\u7136\u540e\u89c6\u56fe DOM \u8fd9\u65b9\u9762\u4f1a\u7531 Vue.js \u81ea\u52a8\u89e3\u51b3\u3002<\/p>\n<p>\u4e8c\u3001\u975e\u5de5\u7a0b\u5316\u8d77\u6b65<\/p>\n<p>\u4e3a\u4e86\u80fd\u652f\u6491\u8d77\u4e00\u4e2a\u6700\u57fa\u672c\u7684\u5e94\u7528\uff0c\u9700\u8981\u5f15\u5165\u4ee5\u4e0b\u51e0\u4e2a\u5fc5\u8981\u6587\u4ef6\uff1a<\/p>\n<ol>\n<li>\n<p>vue.min.2.5.3.js\uff0cvue.js \u5e93<\/p>\n<\/li>\n<li>\n<p>iview.2.7.0.css\uff0ciView \u6837\u5f0f\u6587\u4ef6<\/p>\n<\/li>\n<li>\n<p>iview.min.2.7.0.js\uff0ciView \u5e93<\/p>\n<\/li>\n<li>\n<p>iview \/locale\/zh-CN.js \u8bed\u8a00\u5305<\/p>\n<\/li>\n<li>\n<p>iview \/font \u5b57\u4f53\u5305<\/p>\n<\/li>\n<\/ol>\n<p>\u4e0b\u8f7d Vue.js<\/p>\n<p>\u6765\u5230 Github \u4e0a\u7684 Vue \u9879\u76ee\uff0c\u76f4\u63a5\u4e0b\u8f7d Zip \u6e90\u7801\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/06f564735aa12db3b3b3150fbdef5e42-1.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe1\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe1\" \/><\/p>\n<p>\u5728 dist \u76ee\u5f55\u4e2d\u5c31\u53ef\u4ee5\u627e\u5230 vue.js \u6587\u4ef6\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/06f564735aa12db3b3b3150fbdef5e42-2.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe2\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe2\" \/><\/p>\n<p>\u6839\u636e\u4e0d\u540c\u7684\u73af\u5883\u9009\u62e9\u4e00\u4e2a\u7248\u672c\u5373\u53ef\uff0c\u81f3\u6b64\u7b2c 1 \u6b65\u5c31\u641e\u5b9a\u4e86\u3002<\/p>\n<p>\u4e0b\u8f7d iView \u7cfb\u5217\u6587\u4ef6<\/p>\n<p>\u5728 iView \u5b98\u7f51\u7684\u201c\u7ec4\u4ef6\u201d \/ \u201c\u5b89\u88c5\u201d \u9875\u9762\u7684\u5f00\u5934\u5904\u53d1\u73b0\u4e86\u8fd9\u4e2a\u94fe\u63a5\uff1ahttps:\/\/unpkg.com\/iview\/**\uff0c\u901a\u8fc7\u5b83\u53ef\u4ee5\u67e5\u770b\u5230 dist** \u76ee\u5f55\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/7427f6807bc98abdce6a4a0d9479f999-3.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe3\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe3\" \/><\/p>\n<p>\u5fc5\u8981\u6587\u4ef6\u90fd\u5728\u8fd9\u91cc\uff0c\u8fd9\u4e9b\u6587\u4ef6\u65e0\u6cd5\u6253\u5305\u4e0b\u8f7d\uff0c\u6211\u91c7\u53d6\u7684\u7b28\u529e\u6cd5\u662f\u9010\u4e2a\u70b9\u5f00\uff0c\u7136\u540e\u590d\u5236\u5176\u4e2d\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u5728\u83b7\u53d6 iView \u76f8\u5173\u7684 js \u548c css \u65b9\u9762\u8fd8\u6709\u4e00\u4e2a\u529e\u6cd5\uff0c\u4ed4\u7ec6\u89c2\u5bdf\u5b98\u7f51\u7ed9\u51fa\u7684 CDN \u5730\u5740\u5206\u522b\u4e3a\uff1a<\/p>\n<p>http:\/\/unpkg.com\/iview\/dist\/iview.min.js<br \/>http:\/\/unpkg.com\/iview\/dist\/styles\/iview.css<\/p>\n<p>\u6211\u5c1d\u8bd5\u5c06\u5b83\u4eec\u653e\u5728\u6d4f\u89c8\u5668\u91cc\u8fdb\u884c\u8bbf\u95ee\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/7427f6807bc98abdce6a4a0d9479f999-4.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe4\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe4\" \/><\/p>\n<p>\u53d1\u73b0\u5730\u5740\u6709\u53d8\u66f4\uff0c\u4e0d\u8fc7\u8fd9\u5e76\u65e0\u5927\u788d\u3002<\/p>\n<p>\u81f3\u6b64\uff0c\u5c06\u5404\u4e2a\u6587\u4ef6\u653e\u5728\u671f\u671b\u7684\u4f4d\u7f6e\u5373\u53ef\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/7427f6807bc98abdce6a4a0d9479f999-5.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe5\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe5\" \/><\/p>\n<p>\u8be5\u56fe\u4e2d\u5404\u6587\u4ef6\u7684\u6446\u653e\u5e76\u4e0d\u662f\u5f88\u4e25\u8c28\uff0c\u5927\u5bb6\u6309\u81ea\u5df1\u4e60\u60ef\u6765\u5373\u53ef\u3002<\/p>\n<p>\u4e09\u3001\u5b9e\u4f8b\u6f14\u7ec3<\/p>\n<p>\u5b8c\u6210\u4ee5\u4e0a\u7684\u51c6\u5907\u5de5\u4f5c\u540e\uff0c\u5c31\u53ef\u4ee5\u7ed3\u5408 iView UI \u6765\u6b63\u5f0f\u5f00\u53d1\u4e86\uff0c\u63a5\u4e0b\u6765\u57fa\u4e8e table \u8868\u683c\u7ec4\u4ef6\u6f14\u793a\u4e00\u4e0b\u8d2d\u7269\u8f66\u7684\u57fa\u672c\u64cd\u4f5c\u3002<\/p>\n<p>\u5f15\u5165\u8d44\u6e90<\/p>\n<p>\u7ecf\u8fc7\u8d77\u6b65\u5de5\u4f5c\u7684\u7b79\u5907\uff0c\u53ef\u4ee5\u5728\u65b0\u5efa\u9875\u9762\u4e2d\u9010\u4e2a\u5730\u5f15\u5165\u8fd9\u4e9b\u8d44\u6e90\u3002<\/p>\n<p>HTML head \u90e8\u5206<\/p>\n<pre>&lt;head&gt;\r\n &lt;meta charset=\"UTF-8\"&gt;\r\n &lt;title&gt;\u8d2d\u7269\u8f66\u5b9e\u4f8b&lt;\/title&gt;\r\n &lt;link rel=\"stylesheet\" href=\"iViewContent\/iview.2.7.0.css\" rel=\"external nofollow\" &gt;\r\n &lt;script src=\"utility_js\/vue.min.2.5.3.js\"&gt;&lt;\/script&gt;\r\n &lt;script src=\"utility_js\/iview.min.2.7.0.js\"&gt;&lt;\/script&gt;\r\n &lt;script src=\"iViewContent\/locale\/zh-CN.js\"&gt;&lt;\/script&gt;\r\n &lt;script&gt;\r\n iview.lang('zh-CN');\r\n &lt;\/script&gt;\r\n&lt;\/head&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6309\u4e00\u8d2f\u7684\u65b9\u5f0f\u5f15\u7528\uff0c\u6837\u5f0f\u5c45\u524d\uff0c\u968f\u540e\u7d27\u8ddf\u7740 vue.js \u548c iView.js\uff0c\u4ee5\u53ca iView \u4e2d\u6587\u8bed\u8a00\u5305 zh-CN.js\uff0c\u7136\u540e\u7acb\u5373\u8c03\u7528 lang \u65b9\u6cd5\u4f7f\u5176\u751f\u6548\u3002<\/p>\n<p>\u7ed1\u5b9a\u6570\u636e<\/p>\n<p>\u9996\u5148\u628a\u6570\u636e\u7ed1\u5b9a\u8d77\u6765\uff0c\u4ece\u800c\u770b\u4e00\u770b\u6574\u4f53\u6548\u679c\uff0c\u81f3\u4e8e\u5176\u4ed6\u7684\u884c\u4e3a\u64cd\u4f5c\u5148\u4e0d\u7ba1\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/7427f6807bc98abdce6a4a0d9479f999-6.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe6\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe6\" \/><\/p>\n<p>HTML body \u90e8\u5206<\/p>\n<pre>&lt;body&gt;\r\n &lt;p id=\"app\"&gt;\r\n &lt;i-table id=\"datatable1\"\r\n   size=\"small\"\r\n   :columns=\"columns\"\r\n   :data=\"cartList\"\r\n   stripe\r\n   highlight-row&gt;\r\n &lt;\/i-table&gt;\r\n &lt;\/p&gt;\r\n &lt;script src=\"iViewUI_cart.js\"&gt;&lt;\/script&gt;\r\n&lt;\/body&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7ec4\u4ef6 i-table \u6700\u6838\u5fc3\u7684\u4e24\u4e2a\u5c5e\u6027\u5206\u522b\u662f columns \u548c data\uff0ccolumns \u662f\u5217\u5b9a\u4e49\uff0cdata \u5219\u4e3a\u6570\u636e\u3002<\/p>\n<p>\u8fd9\u4e24\u4e2a\u5c5e\u6027\u90fd\u6dfb\u52a0\u4e86\u5192\u53f7(:)\u8bed\u6cd5\u7cd6\uff0c\u5b83\u6307\u4ee3\u7684\u662f v-bind \u6307\u4ee4\uff0c\u8868\u793a\u8fd9\u4e2a\u5c5e\u6027\u7684\u503c\u662f\u52a8\u6001\u7ed1\u5b9a\u7684\uff0c\u8fd9\u6837\u5728\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u53d1\u73b0\u6570\u636e\u6709\u53d8\u66f4\u65f6\uff0c\u8868\u683c\u89c6\u56fe\u4e5f\u4f1a\u8fc5\u901f\u7684\u53d8\u66f4\u3002<\/p>\n<p>iViewUI_cart.js \u811a\u672c\u90e8\u5206<\/p>\n<pre>var cart = new Vue({\r\n el: '#app',\r\n data: function () {\r\n return {\r\n  cartList: [\r\n  {id: 1, name: 'iPhone X', price: 8300.05, count: 1},\r\n  {id: 2, name: 'MacBook Pro', price: 18800.75, count: 3},\r\n  {id: 3, name: 'Mate 10 Porsche', price: 16600.00, count: 8}\r\n  ],\r\n  columns: [\r\n  {\r\n   title: '\u540d\u79f0',\r\n   key: 'name'\r\n  },\r\n  {\r\n   title: '\u5355\u4ef7',\r\n   key: 'price'\r\n  },\r\n  {\r\n   title: '\u6570\u91cf',\r\n   key: 'count'\r\n  }\r\n  ]\r\n }\r\n },\r\n methods: {}\r\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8be5\u6587\u4ef6\u662f\u4e0e\u9875\u9762\u5bf9\u5e94\u7684\u4e1a\u52a1\u811a\u672c\uff0c\u6574\u4e2a\u6587\u4ef6\u5c31\u8d1f\u8d23 new \u4e00\u4e2a Vue \u5b9e\u4f8b\uff0c\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9\u4e86\u53d8\u91cf cart\uff0c\u53ef\u4ee5\u770b\u5230\u7684 data \u5305\u542b\u4e86\u4e24\u4e2a\u5c5e\u6027\uff0c\u5373\u8868\u793a\u6570\u636e\u6e90\u7684 cartList \u548c \u5217\u5b9a\u4e49\u7684 columns\uff0c\u4e8c\u8005\u6b63\u597d\u4e0e\u4e0a\u8ff0 i-table \u7684\u6838\u5fc3\u5c5e\u6027\u76f8\u6620\u5c04\u3002<\/p>\n<p>\u518d\u6b21\u503c\u5f97\u6ce8\u610f\u7684\u662f data\uff0c\u5b83\u7684\u503c\u9700\u8981\u4ee5\u533f\u540d\u51fd\u6570\u7684\u5f62\u5f0f\u8fdb\u884c\u4e66\u5199\uff0c\u5373\uff1a<\/p>\n<pre>function () {\r\n return {}\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u6b64\uff0c\u5728\u5176 columns \u4e2d\u51fa\u73b0\u7684 Render \u51fd\u6570\u4f53\u5185\u624d\u80fd\u6b63\u5e38\u901a\u8fc7 this \u8bbf\u95ee\u5230 methods \u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5\u3002\u5f53\u7136\u672c\u6b21\u6f14\u793a\u662f\u901a\u8fc7 cart \u5bf9\u8c61\u6765\u8bbf\u95ee\uff0c\u6545\u4e0d\u53d7\u6b64\u5f71\u54cd\u3002<\/p>\n<p>\u8fd0\u884c\u9875\u9762\u540e\uff0c\u6570\u636e\u5373\u53ef\u7ed1\u5b9a\u6210\u529f\u3002<\/p>\n<p>\u6dfb\u52a0\u64cd\u4f5c\u6240\u9700\u6309\u94ae<\/p>\n<p>\u6570\u636e\u5448\u73b0\u51fa\u6765\u540e\uff0c\u5c31\u53ef\u4ee5\u8865\u5145\u5fc5\u8981\u7684\u6309\u94ae\u4e86\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/a5b80395c783d110d5e3db3f198ee8bc-7.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe7\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe7\" \/><\/p>\n<p>\u8fd9\u4e00\u6b65\u7b80\u5355\uff0c\u53ea\u9700\u8981\u4fee\u6539\u4e00\u4e0b columns \u5c5e\u6027\uff0c\u8ffd\u52a0\u4e00\u9879\u201c\u64cd\u4f5c\u201d\u5217\uff0c\u6dfb\u52a0\u4e09\u4e2a\u6309\u94ae\uff1a<\/p>\n<pre>{\r\n title: '\u6570\u91cf',\r\n key: 'count'\r\n},\r\n{\r\n title: '\u64cd\u4f5c',\r\n render: (h, params) =&gt; {\r\n return h('p', [\r\n  h('Button', {\r\n  props: {\r\n   type: 'primary',\r\n   size: 'small'\r\n  },\r\n  style: {\r\n   marginRight: '5px'\r\n  },\r\n  on: {\r\n   click: () =&gt; {\r\n   console.info('\u51cf\u5c11\u6570\u91cf');\r\n   cart.reduceQuantity(params.row.id);\r\n   }\r\n  }\r\n  }, '-'),\r\n  h('Button', {\r\n  props: {\r\n   type: 'primary',\r\n   size: 'small'\r\n  },\r\n  style: {\r\n   marginRight: '5px'\r\n  },\r\n  on: {\r\n   click: () =&gt; {\r\n   console.info('\u589e\u52a0\u6570\u91cf');\r\n   cart.increaseQuantity(params.row.id);\r\n   }\r\n  }\r\n  }, '+'),\r\n  h('Button', {\r\n  props: {\r\n   type: 'error',\r\n   size: 'small'\r\n  },\r\n  style: {\r\n   marginRight: '5px'\r\n  },\r\n  on: {\r\n   click: () =&gt; {\r\n   console.info('\u5220\u9664\u5f53\u524d\u9879');\r\n   cart.deleteItem(params.row.id);\r\n   }\r\n  }\r\n  }, '\u5220\u9664')\r\n ]);\r\n }\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u91cc\u4f7f\u7528\u5230\u4e86 Render \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u7684\u5185\u90e8\u673a\u5236\u7565\u663e\u590d\u6742\uff0c\u4f5c\u4e3a\u521d\u6b65\u6f14\u793a\u53ea\u9700\u4f9d\u6837\u753b\u846b\u82a6\u5373\u53ef\u3002<\/p>\n<p>\u8bf4\u5230 Render \u51fd\u6570\uff0c\u8fd8\u9700\u8981\u518d\u5f3a\u8c03\u4e00\u4e0b\u5728\u5176\u5185\u90e8\u5bf9 methods \u4e2d\u6240\u5b9a\u4e49\u65b9\u6cd5\u7684\u8c03\u7528\uff0c\u5982\u679c\u8bd5\u56fe\u901a\u8fc7 this \u6765\u8c03\u7528\u65b9\u6cd5\uff08\u6bd4\u5982 reduceQuantity\uff09\uff0c\u90a3\u4e48 Vue \u5b9e\u4f8b\u4e2d data \u7684\u503c\u9700\u8981\u4f7f\u7528\u533f\u540d\u51fd\u6570\u7684\u65b9\u5f0f\u6765\u8868\u8fbe\uff1b\u53cd\u4e4b\uff0c\u82e5\u662f\u901a\u8fc7 Vue \u5b9e\u4f8b cart \u6765\u8c03\u7528\uff0c\u5219\u65e0\u6b64\u987e\u8651\uff0c\u5373 data \u7684\u503c\u4f7f\u7528\u4e00\u8d2f\u7684\u5bf9\u8c61\u5927\u62ec\u53f7\uff08{}\uff09\u6765\u8868\u8fbe\u5373\u53ef\u3002<\/p>\n<p>\u6dfb\u52a0\u64cd\u4f5c\u6240\u9700\u65b9\u6cd5<\/p>\n<p>\u64cd\u4f5c\u6309\u94ae\u5df2\u7ecf\u6dfb\u52a0\u6210\u529f\u4e86\uff0c\u90a3\u5c31\u9700\u8981\u6709\u5bf9\u5e94\u7684\u65b9\u6cd5\u53bb\u6267\u884c\uff0c\u5728 Vue.js \u4e2d\uff0c\u65b9\u6cd5\u90fd\u5b9a\u4e49\u5728 methods \u5c5e\u6027\u4e2d\u3002<\/p>\n<p>\u51cf\u53bb\u6570\u91cf<\/p>\n<p>\u9996\u5148\u5173\u6ce8\u4e00\u4e0b\u201c\u51cf\u53bb\u6570\u91cf\u201d\u7684\u5b9a\u4e49\uff1a<\/p>\n<pre>methods: {\r\n reduceQuantity: function (id) {\r\n for (let i = 0; i &lt; this.cartList.length; i++) {\r\n  if (this.cartList[i].id === id) {\r\n  this.cartList[i].count--;\r\n  break;\r\n  }\r\n }\r\n }\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u904d\u5386\u627e\u5230\u76ee\u6807\u8bb0\u5f55\uff0c\u5e76\u5c06\u5176 count \u5c5e\u6027\u51cf\u4e00\uff0c\u5982\u540c MVVM \u7684\u5b9a\u4e49\uff0c\u5f53\u6570\u636e\u53d8\u66f4\u7684\u65f6\u5019\uff0c\u89c6\u56fe\u4e5f\u8ddf\u968f\u7740\u53d8\u5316\u3002<\/p>\n<p>\u4f46\u51e1\u662f\u5b58\u5728\u4e8e\u8d2d\u7269\u8f66\u5185\u7684\u5546\u54c1\uff0c\u5176\u6570\u91cf\u81f3\u5c11\u5e94\u8be5\u4e3a 1\uff0c\u4e3a\u9632\u6b62\u51cf\u5230 0\uff0c\u4e0d\u59a8\u518d\u52a0\u4e00\u4e2a\u5224\u65ad\u4f7f\u5176\u903b\u8f91\u66f4\u4e3a\u5b8c\u7f8e\uff1a<\/p>\n<pre>methods: {\r\n reduceQuantity: function (id) {\r\n for (let i = 0; i &lt; this.cartList.length; i++) {\r\n  if (this.cartList[i].id === id) {\r\n  if (this.cartList[i].count &gt; 1) {\r\n   this.cartList[i].count--;\r\n  }\r\n  break;\r\n  }\r\n }\r\n }\r\n},<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u589e\u52a0\u6570\u91cf<\/p>\n<pre>methods: {\r\n increaseQuantity: function (id) {\r\n for (let i = 0; i &lt; this.cartList.length; i++) {\r\n  if (this.cartList[i].id === id) {\r\n  this.cartList[i].count++;\r\n  break;\r\n  }\r\n }\r\n }\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u53ea\u9700\u8981\u9488\u5bf9 count \u5c5e\u6027\u505a +1 \u64cd\u4f5c\u5373\u53ef\u3002<\/p>\n<p>\u5220\u9664<\/p>\n<pre>deleteItem: function (id) {\r\n for (let i = 0; i &lt; this.cartList.length; i++) {\r\n if (this.cartList[i].id === id) {\r\n  \/\/ \u8be2\u95ee\u662f\u5426\u5220\u9664\r\n  this.$Modal.confirm({\r\n  title: '\u63d0\u793a',\r\n  content: '\u786e\u5b9a\u8981\u5220\u9664\u5417\uff1f',\r\n  onOk: () =&gt; {\r\n   this.cartList.splice(i, 1);\r\n  },\r\n  onCancel: () =&gt; {\r\n   \/\/ \u4ec0\u4e48\u4e5f\u4e0d\u505a\r\n  }\r\n  });\r\n }\r\n }\r\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u5220\u9664\u903b\u8f91\u4e2d\uff0c\u5f53\u904d\u5386\u5230\u76ee\u6807\u8bb0\u5f55\u65f6\uff0c\u4f1a\u8be2\u95ee\u7528\u6237\u662f\u5426\u771f\u7684\u8981\u5220\u9664\u5f53\u524d\u8bb0\u5f55\uff0c\u8fd9\u91cc\u7528\u5230\u4e86 $Modal \u5bf9\u8bdd\u6846\uff0c\u5982\u679c\u7528\u6237\u70b9\u51fb\u786e\u5b9a\uff0c\u90a3\u4e48\u5c31\u6267\u884c\u771f\u6b63\u7684\u5220\u9664\uff0c\u770b\u4e00\u770b\u6548\u679c\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/054\/025\/a5b80395c783d110d5e3db3f198ee8bc-8.png\" class=\"aligncenter\" title=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe8\" alt=\"Vue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\u63d2\u56fe8\" \/><\/p>\n<p>\u975e\u5e38\u6f02\u4eae\u8003\u7a76\u7684 iView Modal \u5bf9\u8bdd\u6846\uff0c\u4ee4\u4eba\u8d4f\u5fc3\u60a6\u76ee\uff0c\u4e00\u89c1\u503e\u5fc3\u3002<\/p>\n<p>\u81f3\u6b64\uff0c\u9488\u5bf9 Vue.js \u548c iView \u6846\u67b6\u7684\u4f53\u9a8c\u5c31\u544a\u4e00\u6bb5\u843d\uff0c\u540e\u9762\u62bd\u65f6\u95f4\u518d\u5b66\u4e60\u4e00\u4e0b\u7ec4\u4ef6\u548c Render \u51fd\u6570\uff0c\u63d0\u5347\u4e00\u4e0b\u5185\u529f\u4fee\u517b\u3002<\/p>\n<p>\u76f8\u5173\u63a8\u8350\uff1a<\/p>\n<\/p>\n<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fVue.js \u4e4b iView UI \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\u5206\u4eab\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>vue.js \u662f\u7f8e\u7c4d\u534e\u4eba\u5c24\u96e8\u6eaa\u521b\u4f5c\u7684\uff0c\u90a3\u4f1a\u513f\u4ed6\u8fd8\u5728 google \u5de5\u4f5c\uff0c\u4ed6\u81ea\u611f angular.js \u7e41\u6742\uff0c\u8fdb\u800c\u81ea\u521b\u4e86\u66f4\u4e3a\u7b80\u6d01\u6613\u7528\u7684 vue.js\u3002\u672c\u6587\u6211\u4eec\u4e3b\u8981\u548c\u5927\u5bb6\u5206\u4eabvue.js \u4e4b iview ui \u6846\u67b6\u975e\u5de5\u7a0b\u5316\u5b9e\u8df5\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u5927\u5bb6\u3002 iView UI \u662f\u7531 90 \u540e\u6881\u704f[h\u00e0o]\u521b\u4f5c\uff0c\u7f51\u540d Aresn\uff0c\u5728\u5927\u6570\u636e\u516c\u53f8 TalkingData \u8d1f\u8d23\u53ef\u89c6\u5316\u57fa\u7840\u67b6\u6784\uff0c\u66f4\u4e86\u4e0d\u8d77\u7684\u662f\u4ed6\u8fd8\u51fa\u4e86\u300aVue.js\u5b9e\u6218\u300b\u4e00\u4e66\uff0c\u6211\u662f\u5728\u201c\u53cc\u5341\u4e00\u201d\u7684\u524d\u4e00\u5929\u4e70\u7684\uff0c\u884c\u6587\u63aa\u8bcd\u7b80\u6d01\uff0c\u8868\u610f\u76f4\u8fbe\u56f0\u60d1\uff0c\u5165\u95e8\u5f88\u8fc5\u901f\uff0c\u662f\u6211\u559c\u6b22\u7684\u98ce\u683c\u3002\u82b1\u4e86\u4e00\u5468\u65f6\u95f4\u626b\u5b8c\u4e86\u524d\u5341\u4e8c\u7ae0\u5185\u5bb9\uff0c\u7528 WebStorm \u7ec3\u4e60\u4e86\u5927\u90e8\u5206\u5b9e\u4f8b\uff0c\u5c3d\u7ba1\u4e66\u4e2d\u7528\u4e00\u6574\u7ae0\u5185\u5bb9\u4ecb\u7ecd\u4e86 webpack \u5de5\u7a0b\u5316\u6784\u5efa\u65b9\u6848\uff0c\u4f46\u7531\u4e8e\u6211\u60ef\u6027\u4f7f\u7136\uff0c\u8fd8\u662f\u9009\u62e9\u5bf9\u5176\u8df3\u8fc7\u800c\u4f7f\u7528\u4e86\u975e\u5de5\u7a0b\u5316\u65b9\u5f0f\u6765\u4f53\u9a8c Vue.js\uff0c\u5176\u5b9e\u591a\u5c11\u6709\u5931\u66b4\u6b84\u3002\u65e0\u5948\uff0c\u6bd5\u7adf\u624d\u5b66\u4e86\u4e00\u5468\uff0c\u540e\u671f\u65f6\u95f4\u5145\u88d5\u4e86\u518d\u63a5\u7740\u5206\u4eab\u5de5\u7a0b\u5316\u6784\u5efa\u7684\u5b66\u4e60\u5fc3\u5f97\u5427\u3002 \u4e00\u3001 MVVM \u6a21\u5f0f Vue.js \u6bd4\u8f83\u663e\u8457\u7684\u7279\u5f81\u662f\u89e3\u8026\u4e86\u89c6\u56fe\u548c\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u8bf4\u89c6\u56fe\u7684\u53d8\u5316\u4e0d\u518d\u9700\u8981\u547d\u4ee4\u5f0f\u7f16\u7a0b\u53bb\u663e\u5f0f\u6539\u53d8\uff0c\u53ea\u8981\u4fee\u6539\u5b8c\u6570\u636e\u5c31\u80fd\u7acb\u5373\u81ea\u52a8\u540c\u6b65\uff0c\u8fd9\u662f\u6bd4\u8f83\u5927\u7684\u4e00\u4e2a\u601d\u7ef4\u6a21\u5f0f\u7684\u8f6c\u53d8\uff0c\u53e6\u4e00\u4e2a\u5c31\u662f\u7ec4\u4ef6\u5316\u601d\u7ef4\u4fef\u9996\u7686\u662f\uff0c\u8fd9\u6837\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u5c31\u76f8\u5f53\u662f\u5728\u642d\u79ef\u6728\u3002 \u5176\u5b9e\u4ee5\u4e0a\u5bf9 Vue.js \u6240\u9610\u8ff0\u7684\u4f18\u70b9\u4e5f\u6b63\u662f MVVM \u6a21\u5f0f\u7684\u5199\u7167\uff0c\u5b83\u539f\u662f\u7531 MVC \u6240\u884d\u751f\uff0c\u5373\u5f53\u89c6\u56fe\u5c42\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u4f1a\u81ea\u52a8\u66f4\u65b0\u5230\u89c6\u56fe\u6a21\u578b\u4e0a\uff0c\u53cd\u4e4b\u4ea6\u7136\uff0c\u8fd9\u5c31\u662f\u5e38\u8bf4\u7684\u53cc\u5411\u7ed1\u5b9a\uff0c\u4e0a\u4e00\u5f20\u56fe\u5427\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u752d\u7ba1\u8fd9\u56fe\u662f\u5426\u597d\u7406\u89e3\uff0c\u901a\u4fd7\u5730\u6765\u8bb2\uff0cMVVM \u8fd9\u79cd\u6a21\u5f0f\u62c6\u5206\u4e86\u89c6\u56fe\u548c\u6570\u636e\uff0c\u8fd9\u6837\u6211\u4eec\u5728\u5f00\u53d1\u65f6\u53ea\u8981\u5173\u5fc3\u6570\u636e\u672c\u8eab\u5373\u53ef\uff0c\u7136\u540e\u89c6\u56fe DOM \u8fd9\u65b9\u9762\u4f1a\u7531 Vue.js \u81ea\u52a8\u89e3\u51b3\u3002 \u4e8c\u3001\u975e\u5de5\u7a0b\u5316\u8d77\u6b65 \u4e3a\u4e86\u80fd\u652f\u6491\u8d77\u4e00\u4e2a\u6700\u57fa\u672c\u7684\u5e94\u7528\uff0c\u9700\u8981\u5f15\u5165\u4ee5\u4e0b\u51e0\u4e2a\u5fc5\u8981\u6587\u4ef6\uff1a vue.min.2.5.3.js\uff0cvue.js \u5e93 iview.2.7.0.css\uff0ciView \u6837\u5f0f\u6587\u4ef6 iview.min.2.7.0.js\uff0ciView \u5e93 iview \/locale\/zh-CN.js \u8bed\u8a00\u5305 iview [&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-31144","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31144","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=31144"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/31144\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=31144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=31144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=31144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}