{"id":8573,"date":"2023-11-28T20:31:37","date_gmt":"2023-11-28T12:31:37","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=8573"},"modified":"2023-12-02T23:05:40","modified_gmt":"2023-12-02T15:05:40","slug":"vue-zhong-vue-zhong-transition-de-li-jie","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/vue-zhong-vue-zhong-transition-de-li-jie\/","title":{"rendered":"Vue \u4e2d vue \u4e2d transition \u7684\u7406\u89e3\uff1f"},"content":{"rendered":"<p>\u5728 Vue \u4e2d\uff0c<code>&lt;transition&gt;<\/code> \u662f\u4e00\u4e2a\u7528\u4e8e\u5728 Vue \u7ec4\u4ef6\u4e2d\u5b9e\u73b0\u8fc7\u6e21\u6548\u679c\u7684\u62bd\u8c61\u7ec4\u4ef6\u3002\u5b83\u53ef\u4ee5\u8ba9\u5143\u7d20\u5728\u63d2\u5165\u3001\u66f4\u65b0\u6216\u79fb\u9664\u65f6\u4ee5\u4e00\u79cd\u6e10\u8fdb\u7684\u65b9\u5f0f\u6539\u53d8\u3002<\/p>\n<h3><a id=\"1%E8%BF%87%E6%B8%A1%E7%9A%84%E5%9F%BA%E6%9C%AC%E7%94%A8%E6%B3%95\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>1. \u8fc7\u6e21\u7684\u57fa\u672c\u7528\u6cd5<\/h3>\n<p>\u4f7f\u7528 <code>&lt;transition&gt;<\/code> \u7ec4\u4ef6\u5305\u88f9\u8981\u8fdb\u884c\u8fc7\u6e21\u7684\u5143\u7d20\uff0c\u5e76\u63d0\u4f9b CSS \u7c7b\u540d\u6765\u5b9a\u4e49\u8fc7\u6e21\u6548\u679c\uff1a<\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div&gt;\n    &lt;transition name=&quot;fade&quot;&gt;\n      &lt;p v-if=&quot;show&quot;&gt;This will transition&lt;\/p&gt;\n    &lt;\/transition&gt;\n    &lt;button @click=&quot;toggle&quot;&gt;Toggle&lt;\/button&gt;\n  &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  data() {\n    return {\n      show: false,\n    };\n  },\n  methods: {\n    toggle() {\n      this.show = !this.show;\n    },\n  },\n};\n&lt;\/script&gt;\n\n&lt;style&gt;\n.fade-enter-active, .fade-leave-active {\n  transition: opacity 0.5s;\n}\n.fade-enter, .fade-leave-to {\n  opacity: 0;\n}\n&lt;\/style&gt;\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53 <code>show<\/code> \u53d8\u91cf\u4e3a <code>true<\/code> \u65f6\uff0c\u6bb5\u843d\u5143\u7d20\u4f1a\u4ee5\u6de1\u5165\u6de1\u51fa\u7684\u65b9\u5f0f\u663e\u793a\u548c\u9690\u85cf\uff0c\u89e6\u53d1\u8fc7\u6e21\u6548\u679c\u3002<\/p>\n<h3><a id=\"2%E8%BF%87%E6%B8%A1%E9%92%A9%E5%AD%90\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>2. \u8fc7\u6e21\u94a9\u5b50<\/h3>\n<p><code>&lt;transition&gt;<\/code> \u7ec4\u4ef6\u63d0\u4f9b\u4e86\u591a\u4e2a\u94a9\u5b50\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u6765\u5728\u4e0d\u540c\u9636\u6bb5\u89e6\u53d1\u8fc7\u6e21\u6548\u679c\uff0c\u4f8b\u5982 <code>before-enter<\/code>\u3001<code>enter<\/code>\u3001<code>after-enter<\/code>\u3001<code>before-leave<\/code>\u3001<code>leave<\/code>\u3001<code>after-leave<\/code> \u7b49\u3002<\/p>\n<pre><code class=\"language-vue\">&lt;transition\n  name=&quot;fade&quot;\n  @before-enter=&quot;beforeEnter&quot;\n  @enter=&quot;enter&quot;\n  @after-enter=&quot;afterEnter&quot;\n&gt;\n  &lt;!-- ... --&gt;\n&lt;\/transition&gt;\n<\/code><\/pre>\n<h3><a id=\"3%E8%BF%87%E6%B8%A1%E6%A8%A1%E5%BC%8F\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>3. \u8fc7\u6e21\u6a21\u5f0f<\/h3>\n<p><code>&lt;transition&gt;<\/code> \u7ec4\u4ef6\u8fd8\u652f\u6301\u4e0d\u540c\u7684\u8fc7\u6e21\u6a21\u5f0f\uff0c\u6bd4\u5982 <code>in-out<\/code>\u3001<code>out-in<\/code>\uff0c\u8fd9\u4e9b\u6a21\u5f0f\u53ef\u4ee5\u51b3\u5b9a\u540c\u65f6\u89e6\u53d1\u591a\u4e2a\u5143\u7d20\u7684\u8fc7\u6e21\u65f6\u7684\u884c\u4e3a\u3002<\/p>\n<pre><code class=\"language-vue\">&lt;transition mode=&quot;out-in&quot;&gt;\n  &lt;!-- ... --&gt;\n&lt;\/transition&gt;\n<\/code><\/pre>\n<p>\u8fc7\u6e21\u6548\u679c\u662f\u5728\u5143\u7d20\u63d2\u5165\u3001\u66f4\u65b0\u6216\u79fb\u9664\u65f6\u89e6\u53d1\u7684\uff0c\u901a\u8fc7\u7ed3\u5408 CSS \u8fc7\u6e21\u6548\u679c\u548c Vue \u63d0\u4f9b\u7684\u8fc7\u6e21\u94a9\u5b50\u51fd\u6570\uff0c\u53ef\u4ee5\u521b\u5efa\u5404\u79cd\u5404\u6837\u7684\u8fc7\u6e21\u52a8\u753b\u6548\u679c\uff0c\u4f7f\u5f97\u9875\u9762\u5728\u53d8\u5316\u65f6\u663e\u5f97\u66f4\u52a0\u5e73\u6ed1\u548c\u81ea\u7136\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Vue \u4e2d\uff0c&lt;transition&gt; \u662f\u4e00\u4e2a\u7528\u4e8e\u5728 Vue \u7ec4\u4ef6\u4e2d\u5b9e\u73b0\u8fc7\u6e21\u6548\u679c\u7684\u62bd\u8c61\u7ec4\u4ef6\u3002\u5b83\u53ef [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[],"class_list":["post-8573","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=8573"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8573\/revisions"}],"predecessor-version":[{"id":14134,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8573\/revisions\/14134"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=8573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=8573"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=8573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}