{"id":53502,"date":"2024-12-03T10:20:29","date_gmt":"2024-12-03T02:20:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53502\/"},"modified":"2024-12-03T10:20:29","modified_gmt":"2024-12-03T02:20:29","slug":"vue3-element-plus-%e4%b8%ad%ef%bc%8cthis-emit-%e5%a4%b1%e6%95%88%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\/53502\/","title":{"rendered":"VUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>VUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aVUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241201\/1733023287674bd6377aa72.jpg\" class=\"aligncenter\" title=\"VUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"VUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>vue3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u95ee\u9898<\/strong><\/p>\n<p><strong>\u95ee\u9898\u63cf\u8ff0\uff1a<\/strong><br \/>\u5728 vue3 + element-plus \u4e2d\uff0c\u5b50\u7ec4\u4ef6\u5411\u7236\u7ec4\u4ef6\u53d1\u9001\u6d88\u606f\u65f6\uff0c\u53d1\u73b0 this.$emit \u65b9\u6cd5\u65e0\u6548\uff0c\u65e0\u6cd5\u89e6\u53d1\u7236\u7ec4\u4ef6\u4e2d\u7684\u51fd\u6570\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>this.$emit \u5931\u6548\u901a\u5e38\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\u5bfc\u81f4\u7684\uff1a<\/p>\n<ol>\n<li><strong>\u672a\u6b63\u786e\u4f20\u9012 props\uff1a<\/strong><br \/>\u786e\u4fdd\u7236\u7ec4\u4ef6\u5df2\u7ecf\u5c06\u51fd\u6570\u4f5c\u4e3a props \u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u3002<\/li>\n<li><strong>\u672a\u6b63\u786e\u89e6\u53d1\u4e8b\u4ef6\uff1a<\/strong><br \/>\u5b50\u7ec4\u4ef6\u9700\u8981\u89e6\u53d1 this.$emit() \u65b9\u6cd5\u4ee5\u89e6\u53d1\u4e8b\u4ef6\uff0c\u8fdb\u800c\u8c03\u7528\u7236\u7ec4\u4ef6\u4e2d\u7684\u51fd\u6570\u3002<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u63d0\u4f9b\u4e24\u79cd\u5b9e\u73b0\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 props \u4f20\u9012\u51fd\u6570<\/strong><\/p>\n<pre>\/\/ \u7236\u7ec4\u4ef6\n&lt;newnew\n    ...\n    :update=\"conditionupdate\"\n\/&gt;\n\n\/\/ \u5b50\u7ec4\u4ef6\n&lt;script&gt;\n    props: [..., 'update'],\n    ...\n    methods: {\n        confirm() {\n            this.update(xxx);\n        }\n    }\n&lt;\/script&gt;<\/pre>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528\u4e8b\u4ef6\u89e6\u53d1<\/strong><\/p>\n<pre>\/\/ \u7236\u7ec4\u4ef6\n&lt;newnew\n    ...\n    @update=\"conditionUpdate\"\n\/&gt;\n\n\/\/ \u5b50\u7ec4\u4ef6\n&lt;script&gt;\n    props: [..., 'update'],\n    ...\n    methods: {\n        confirm() {\n            this.$emit('update', xxx); \/\/ \u5b50\u7ec4\u4ef6\u89e6\u53d1\u4e86 update \u4e8b\u4ef6\uff0c\u8fdb\u800c\u8c03\u7528\u7236\u7ec4\u4ef6\u4e2d\u7ed1\u5b9a\u7684 conditionUpdate \u51fd\u6570\n        }\n    }\n&lt;\/script&gt;<\/pre>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u60a8\u4f7f\u7528\u7684\u662f\u6b63\u786e\u7684\u5b50\u7ec4\u4ef6\u540d\u79f0\u3002<\/li>\n<li>\u786e\u4fdd\u5b50\u7ec4\u4ef6\u5df2\u7ecf\u88ab\u5bfc\u5165\u5e76\u6ce8\u518c\u4e3a vue \u7ec4\u4ef6\u3002<\/li>\n<li>\u68c0\u67e5\u7236\u5b50\u7ec4\u4ef6\u4e4b\u95f4\u7684\u901a\u4fe1\u662f\u5426\u6709\u4efb\u4f55\u9519\u8bef\u3002<\/li>\n<\/ul>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aVUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   win10\u84dd\u7259\u9f20\u6807\u7ecf\u5e38\u6389\u7ebf\u600e\u4e48\u529e\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>VUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f \u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300aVUE3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u539f\u56e0\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01 vue3 + element-plus \u4e2d\uff0cthis.$emit \u5931\u6548\u7684\u95ee\u9898 \u95ee\u9898\u63cf\u8ff0\uff1a\u5728 vue3 + element-plus \u4e2d\uff0c\u5b50\u7ec4\u4ef6\u5411\u7236\u7ec4\u4ef6\u53d1\u9001\u6d88\u606f\u65f6\uff0c\u53d1\u73b0 this.$emit \u65b9\u6cd5\u65e0\u6548\uff0c\u65e0\u6cd5\u89e6\u53d1\u7236\u7ec4\u4ef6\u4e2d\u7684\u51fd\u6570\u3002 \u89e3\u51b3\u65b9\u6848\uff1a this.$emit \u5931\u6548\u901a\u5e38\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\u5bfc\u81f4\u7684\uff1a \u672a\u6b63\u786e\u4f20\u9012 props\uff1a\u786e\u4fdd\u7236\u7ec4\u4ef6\u5df2\u7ecf\u5c06\u51fd\u6570\u4f5c\u4e3a props \u4f20\u9012\u7ed9\u5b50\u7ec4\u4ef6\u3002 \u672a\u6b63\u786e\u89e6\u53d1\u4e8b\u4ef6\uff1a\u5b50\u7ec4\u4ef6\u9700\u8981\u89e6\u53d1 this.$emit() \u65b9\u6cd5\u4ee5\u89e6\u53d1\u4e8b\u4ef6\uff0c\u8fdb\u800c\u8c03\u7528\u7236\u7ec4\u4ef6\u4e2d\u7684\u51fd\u6570\u3002 \u4e0b\u9762\u63d0\u4f9b\u4e24\u79cd\u5b9e\u73b0\u65b9\u6cd5\uff1a \u65b9\u6cd5 1\uff1a\u4f7f\u7528 props \u4f20\u9012\u51fd\u6570 \/\/ \u7236\u7ec4\u4ef6 &lt;newnew &#8230; :update=&#8221;conditionupdate&#8221; \/&gt; \/\/ \u5b50\u7ec4\u4ef6 &lt;script&gt; props: [&#8230;, &#8216;update&#8217;], &#8230; methods: { confirm() { this.update(xxx); [&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-53502","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53502","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=53502"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53502\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53502"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53502"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53502"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}