{"id":27067,"date":"2024-11-24T10:14:41","date_gmt":"2024-11-24T02:14:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27067\/"},"modified":"2024-11-24T10:14:41","modified_gmt":"2024-11-24T02:14:41","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e7%9b%91%e5%90%ac-props-%e5%ae%9e%e7%8e%b0-vue-js-%e4%b8%ad%e8%87%aa%e5%ae%9a%e4%b9%89%e5%bc%b9%e7%aa%97%e7%9a%84%e6%98%be%e7%a4%ba%e5%88%87%e6%8d%a2%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27067\/","title":{"rendered":"\u5982\u4f55\u901a\u8fc7\u76d1\u542c props \u5b9e\u73b0 Vue.js \u4e2d\u81ea\u5b9a\u4e49\u5f39\u7a97\u7684\u663e\u793a\u5207\u6362\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173115396325455.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u901a\u8fc7\u76d1\u542c props \u5b9e\u73b0 Vue.js \u4e2d\u81ea\u5b9a\u4e49\u5f39\u7a97\u7684\u663e\u793a\u5207\u6362\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u901a\u8fc7\u76d1\u542c props \u5b9e\u73b0 Vue.js \u4e2d\u81ea\u5b9a\u4e49\u5f39\u7a97\u7684\u663e\u793a\u5207\u6362\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u901a\u8fc7\u76d1\u542c props \u5b9e\u73b0\u81ea\u5b9a\u4e49\u5f39\u7a97\u663e\u793a\u5207\u6362<\/strong><\/p>\n<p>\u5728 Vue.js \u4e2d\uff0c\u5f53\u4f7f\u7528 dialog \u7ec4\u4ef6\u65f6\uff0c\u901a\u8fc7 visible prop \u63a7\u5236\u663e\u793a\u548c\u9690\u85cf\u3002\u7136\u800c\uff0c\u5728\u67d0\u573a\u666f\u4e0b\uff0c\u5e0c\u671b\u901a\u8fc7\u4fee\u6539 dialog \u7ec4\u4ef6\u5185\u7684\u4ee3\u7801\u5b9e\u73b0\u663e\u793a\u5207\u6362\u3002<\/p>\n<p>\u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u9700\u8981\u76d1\u542c visible prop \u7684\u53d8\u5316\uff0c\u5e76\u540c\u6b65\u66f4\u65b0\u5185\u90e8\u72b6\u6001 visibleMe\u3002\u5f53\u8c03\u7528 closeDialog \u65b9\u6cd5\u65f6\uff0c\u5c06 visibleMe \u8bbe\u4e3a false\uff0c\u5e76\u901a\u8fc7 $emit \u624b\u52a8\u89e6\u53d1\u7236\u7ec4\u4ef6\u7684 update:visible \u4e8b\u4ef6\uff0c\u5c06 visible \u7684\u503c\u66f4\u65b0\u4e3a false\u3002<\/p>\n<p>\u4fee\u6539\u540e\u7684 dialog \u7ec4\u4ef6\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>&lt;template&gt;\n  &lt;div v-if=\"visibleMe\"&gt;\n    &lt;!-- \u5185\u5bb9 --&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  props: {\n    visible: Boolean,\n  },\n  data() {\n    return {\n      visibleMe: this.visible, \/\/ \u521d\u59cb\u5316 visibleMe \u4e3a visible \u7684\u521d\u59cb\u503c\n    };\n  },\n  watch: {\n    visible(newVal) {\n      this.visibleMe = newVal; \/\/ \u5f53 visible \u53d1\u751f\u53d8\u5316\u65f6\uff0c\u66f4\u65b0 visibleMe\n    },\n  },\n  methods: {\n    closeDialog() {\n      this.visibleMe = false;\n      this.$emit('update:visible', false); \/\/ \u89e6\u53d1 update:visible \u4e8b\u4ef6\uff0c\u66f4\u65b0\u7236\u7ec4\u4ef6\u7684 visible\n    },\n  },\n};\n&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4e0a\u8ff0\u4fee\u6539\uff0c\u4ec5\u9700\u4fee\u6539 dialog \u7ec4\u4ef6\u7684\u4ee3\u7801\uff0c\u5373\u53ef\u901a\u8fc7\u76d1\u542c visible prop \u5b9e\u73b0\u81ea\u5b9a\u4e49\u5f39\u7a97\u7684\u663e\u793a\u5207\u6362\u3002<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u901a\u8fc7\u76d1\u542c props \u5b9e\u73b0 Vue.js \u4e2d\u81ea\u5b9a\u4e49\u5f39\u7a97\u7684\u663e\u793a\u5207\u6362\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>\u901a\u8fc7\u76d1\u542c props \u5b9e\u73b0\u81ea\u5b9a\u4e49\u5f39\u7a97\u663e\u793a\u5207\u6362 \u5728 Vue.js \u4e2d\uff0c\u5f53\u4f7f\u7528 dialog \u7ec4\u4ef6\u65f6\uff0c\u901a\u8fc7 visible prop \u63a7\u5236\u663e\u793a\u548c\u9690\u85cf\u3002\u7136\u800c\uff0c\u5728\u67d0\u573a\u666f\u4e0b\uff0c\u5e0c\u671b\u901a\u8fc7\u4fee\u6539 dialog \u7ec4\u4ef6\u5185\u7684\u4ee3\u7801\u5b9e\u73b0\u663e\u793a\u5207\u6362\u3002 \u4e3a\u4e86\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\uff0c\u9700\u8981\u76d1\u542c visible prop \u7684\u53d8\u5316\uff0c\u5e76\u540c\u6b65\u66f4\u65b0\u5185\u90e8\u72b6\u6001 visibleMe\u3002\u5f53\u8c03\u7528 closeDialog \u65b9\u6cd5\u65f6\uff0c\u5c06 visibleMe \u8bbe\u4e3a false\uff0c\u5e76\u901a\u8fc7 $emit \u624b\u52a8\u89e6\u53d1\u7236\u7ec4\u4ef6\u7684 update:visible \u4e8b\u4ef6\uff0c\u5c06 visible \u7684\u503c\u66f4\u65b0\u4e3a false\u3002 \u4fee\u6539\u540e\u7684 dialog \u7ec4\u4ef6\u4ee3\u7801\u5982\u4e0b\uff1a &lt;template&gt; &lt;div v-if=&#8221;visibleMe&#8221;&gt; &lt;!&#8211; \u5185\u5bb9 &#8211;&gt; &lt;\/div&gt; &lt;\/template&gt; &lt;script&gt; export default { props: { visible: Boolean, }, data() { return { visibleMe: [&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-27067","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27067","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=27067"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27067\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}