{"id":3846,"date":"2024-11-10T11:05:55","date_gmt":"2024-11-10T03:05:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3846\/"},"modified":"2024-11-10T11:05:55","modified_gmt":"2024-11-10T03:05:55","slug":"vue-js-%e4%b8%ad-dialog-%e7%bb%84%e4%bb%b6%e7%9a%84-visible-%e5%b1%9e%e6%80%a7%e6%97%a0%e6%b3%95%e8%a7%a6%e5%8f%91%e7%9b%91%e5%90%ac%ef%bc%8c%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87%e4%bf%ae%e6%94%b9","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3846\/","title":{"rendered":"Vue.js \u4e2d Dialog \u7ec4\u4ef6\u7684 visible \u5c5e\u6027\u65e0\u6cd5\u89e6\u53d1\u76d1\u542c\uff0c\u5982\u4f55\u901a\u8fc7\u4fee\u6539\u7ec4\u4ef6\u4ee3\u7801\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173115219061845.jpg\" class=\"aligncenter\" title=\"Vue.js \u4e2d Dialog \u7ec4\u4ef6\u7684 visible \u5c5e\u6027\u65e0\u6cd5\u89e6\u53d1\u76d1\u542c\uff0c\u5982\u4f55\u901a\u8fc7\u4fee\u6539\u7ec4\u4ef6\u4ee3\u7801\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"Vue.js \u4e2d Dialog \u7ec4\u4ef6\u7684 visible \u5c5e\u6027\u65e0\u6cd5\u89e6\u53d1\u76d1\u542c\uff0c\u5982\u4f55\u901a\u8fc7\u4fee\u6539\u7ec4\u4ef6\u4ee3\u7801\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u81ea\u5b9a\u4e49\u5f39\u7a97\u663e\u793a\u63a7\u5236<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 Vue.js \u7684 Dialog \u7ec4\u4ef6\u65f6\uff0c\u901a\u8fc7\u8bbe\u7f6e visible \u5c5e\u6027\u53ef\u4ee5\u63a7\u5236\u5f39\u7a97\u7684\u663e\u793a\uff0c\u7136\u800c\u76f4\u63a5\u4fee\u6539 visible \u5c5e\u6027\u4f1a\u5bfc\u81f4\u65e0\u6cd5\u89e6\u53d1 Dialog \u5185\u90e8\u5bf9 visible \u53d8\u5316\u7684\u76d1\u542c\u3002\u5982\u4f55\u901a\u8fc7\u4fee\u6539 Dialog \u7ec4\u4ef6\u672c\u8eab\u7684\u4ee3\u7801\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f<\/p>\n<p><strong>\u7b54\u6848\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\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\u60c5\u51b5\u4e0b\u53d6\u81ea prop\n    };\n  },\n  watch: {\n    visible(newVal) {\n      this.visibleMe = newVal; \/\/ \u4ece prop \u540c\u6b65 visibleMe\n    },\n  },\n  methods: {\n    closeDialog() {\n      this.visibleMe = false;\n      this.$emit('update:visible', false); \/\/ \u5411\u7236\u7ec4\u4ef6\u66f4\u65b0 prop\n    },\n  },\n};\n&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u4ee3\u7801\u4e2d\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ol>\n<li>\u4f7f\u7528 v-if=&#8221;visibleMe&#8221; \u66ff\u4ee3 v-if=&#8221;visible&#8221;\uff0c\u4ee5\u4ece visibleMe \u6570\u636e\u63a5\u6536\u63a7\u5236\u3002<\/li>\n<li>\u5728 data() \u4e2d\u521d\u59cb\u5316 visibleMe \u4e3a this.visible\uff0c\u5728\u7ec4\u4ef6\u521b\u5efa\u65f6\u4ece visible prop \u83b7\u53d6\u521d\u59cb\u503c\u3002<\/li>\n<li>\u6dfb\u52a0\u4e00\u4e2a closeDialog() \u65b9\u6cd5\uff0c\u5b83\u5c06 visibleMe \u8bbe\u7f6e\u4e3a false\uff0c\u5e76\u901a\u8fc7 $emit(&#8216;update:visible&#8217;, false) \u4e8b\u4ef6\u66f4\u65b0\u7236\u7ec4\u4ef6\u4e2d\u7684 visible prop\u3002<\/li>\n<li>\u4f7f\u7528 watch \u6765\u76d1\u542c visible prop \u7684\u53d8\u5316\uff0c\u5e76\u5728\u53d8\u5316\u65f6\u66f4\u65b0 visibleMe\u3002<\/li>\n<\/ol>\n<p>\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5728\u4fee\u6539 Dialog \u7ec4\u4ef6\u5185\u90e8\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u5b9e\u73b0\u81ea\u5b9a\u4e49\u5f39\u7a97\u663e\u793a\u63a7\u5236\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fVue.js \u4e2d Dialog \u7ec4\u4ef6\u7684 visible \u5c5e\u6027\u65e0\u6cd5\u89e6\u53d1\u76d1\u542c\uff0c\u5982\u4f55\u901a\u8fc7\u4fee\u6539\u7ec4\u4ef6\u4ee3\u7801\u89e3\u51b3\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>\u81ea\u5b9a\u4e49\u5f39\u7a97\u663e\u793a\u63a7\u5236 \u5728\u4f7f\u7528 Vue.js \u7684 Dialog \u7ec4\u4ef6\u65f6\uff0c\u901a\u8fc7\u8bbe\u7f6e visible \u5c5e\u6027\u53ef\u4ee5\u63a7\u5236\u5f39\u7a97\u7684\u663e\u793a\uff0c\u7136\u800c\u76f4\u63a5\u4fee\u6539 visible \u5c5e\u6027\u4f1a\u5bfc\u81f4\u65e0\u6cd5\u89e6\u53d1 Dialog \u5185\u90e8\u5bf9 visible \u53d8\u5316\u7684\u76d1\u542c\u3002\u5982\u4f55\u901a\u8fc7\u4fee\u6539 Dialog \u7ec4\u4ef6\u672c\u8eab\u7684\u4ee3\u7801\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u5462\uff1f \u7b54\u6848\uff1a \u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u4ee3\u7801\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: this.visible, \/\/ \u521d\u59cb\u60c5\u51b5\u4e0b\u53d6\u81ea prop }; }, watch: { visible(newVal) { this.visibleMe = newVal; \/\/ \u4ece [&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-3846","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3846","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=3846"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3846\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}