{"id":53497,"date":"2024-12-03T17:32:18","date_gmt":"2024-12-03T09:32:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53497\/"},"modified":"2024-12-03T17:32:18","modified_gmt":"2024-12-03T09:32:18","slug":"vue3-%e6%95%b0%e7%bb%84%e5%8e%bb%e9%87%8d%e5%90%8e%e5%87%ba%e7%8e%b0-proxyobject-%e6%95%b0%e6%8d%ae%e7%9a%84%e5%8e%9f%e5%9b%a0%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53497\/","title":{"rendered":"Vue3 \u6570\u7ec4\u53bb\u91cd\u540e\u51fa\u73b0 Proxy(Object) \u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Vue3 \u6570\u7ec4\u53bb\u91cd\u540e\u51fa\u73b0 Proxy(Object) \u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p><span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aVue3 \u6570\u7ec4\u53bb\u91cd\u540e\u51fa\u73b0 Proxy(Object) \u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241201\/1733018796674bc4ac2461c.jpg\" class=\"aligncenter\" title=\"Vue3 \u6570\u7ec4\u53bb\u91cd\u540e\u51fa\u73b0 Proxy(Object) \u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"Vue3 \u6570\u7ec4\u53bb\u91cd\u540e\u51fa\u73b0 Proxy(Object) \u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<h2>vue3 \u53bb\u91cd\u540e\u51fa\u73b0 proxy(object) \u6570\u636e\u7684\u539f\u56e0<\/h2>\n<p>\u5728 vue3 \u4e2d\uff0c\u5229\u7528 set \u8fdb\u884c\u6570\u7ec4\u53bb\u91cd\u64cd\u4f5c\u540e\uff0c\u53ef\u80fd\u4f1a\u989d\u5916\u51fa\u73b0 proxy(object) \u7684\u6570\u636e\uff0c\u539f\u56e0\u5982\u4e0b\uff1a<\/p>\n<h3>1. ref \u6570\u636e\u5904\u7406<\/h3>\n<p>vue3 \u4e2d\u4f7f\u7528 ref \u51fa\u6765\u7684\u6570\u636e\u7ecf\u8fc7\u7279\u6b8a\u5904\u7406\u3002\u5982\u679c\u60a8\u5728\u6570\u7ec4\u53bb\u91cd\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7684\u662f ref \u51fa\u6765\u7684\u6570\u636e\uff0c\u5219\u9700\u8981\u8c03\u7528 toraw \u65b9\u6cd5\u6765\u53bb\u9664\u8be5\u5904\u7406\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>const obj = ref({\n  serviceattributelist: [\n    {\n      name: 'duo',\n    },\n    {\n      name: 'emma',\n    },\n  ],\n});\n\nconst set = new set([...obj.value.serviceattributelist]);\nobj.serviceattributelist = [...new set(set)];<\/pre>\n<p><strong>\u4fee\u6539\u540e\uff1a<\/strong><\/p>\n<pre>const obj = ref({\n  serviceattributelist: [\n    {\n      name: 'duo',\n    },\n    {\n      name: 'emma',\n    },\n  ],\n});\n\nconst set = new set([...toraw(obj.value.serviceattributelist)]);\nobj.serviceattributelist = [...new set(set)];<\/pre>\n<h3>2. \u5bf9\u8c61\u6570\u7ec4\u53bb\u91cd<\/h3>\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cset \u65e0\u6cd5\u5bf9\u5bf9\u8c61\u6570\u7ec4\u8fdb\u884c\u53bb\u91cd\u3002\u5982\u679c\u60a8\u9700\u8981\u5bf9\u5bf9\u8c61\u6570\u7ec4\u53bb\u91cd\uff0c\u9700\u8981\u5c06\u5bf9\u8c61\u8f6c\u6362\u4e3a\u5b57\u7b26\u4e32\u540e\u518d\u8fdb\u884c\u53bb\u91cd\u3002<\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>obj.serviceAttributeList = [...new Set(result.map(JSON.stringify))].map(\n  JSON.parse\n);<\/pre>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5bcc\u58eb\u901a\u7b14\u8bb0\u672c\u7535\u8111\u5982\u4f55\u62c6\u88c5\u952e\u76d8\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Vue3 \u6570\u7ec4\u53bb\u91cd\u540e\u51fa\u73b0 Proxy(Object) \u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f \u6587\u7ae0\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u300aVue3 \u6570\u7ec4\u53bb\u91cd\u540e\u51fa\u73b0 Proxy(Object) \u6570\u636e\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01 vue3 \u53bb\u91cd\u540e\u51fa\u73b0 proxy(object) \u6570\u636e\u7684\u539f\u56e0 \u5728 vue3 \u4e2d\uff0c\u5229\u7528 set \u8fdb\u884c\u6570\u7ec4\u53bb\u91cd\u64cd\u4f5c\u540e\uff0c\u53ef\u80fd\u4f1a\u989d\u5916\u51fa\u73b0 proxy(object) \u7684\u6570\u636e\uff0c\u539f\u56e0\u5982\u4e0b\uff1a 1. ref \u6570\u636e\u5904\u7406 vue3 \u4e2d\u4f7f\u7528 ref \u51fa\u6765\u7684\u6570\u636e\u7ecf\u8fc7\u7279\u6b8a\u5904\u7406\u3002\u5982\u679c\u60a8\u5728\u6570\u7ec4\u53bb\u91cd\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u7684\u662f ref \u51fa\u6765\u7684\u6570\u636e\uff0c\u5219\u9700\u8981\u8c03\u7528 toraw \u65b9\u6cd5\u6765\u53bb\u9664\u8be5\u5904\u7406\u3002 \u793a\u4f8b\uff1a const obj = ref({ serviceattributelist: [ { name: &#8216;duo&#8217;, }, { name: &#8217;emma&#8217;, }, ], }); const set = new set([&#8230;obj.value.serviceattributelist]); obj.serviceattributelist = [&#8230;new [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-53497","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53497","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=53497"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53497\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53497"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53497"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53497"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}