{"id":983,"date":"2023-03-23T22:41:43","date_gmt":"2023-03-23T14:41:43","guid":{"rendered":""},"modified":"2023-03-23T22:41:43","modified_gmt":"2023-03-23T14:41:43","slug":"vue.js \u8f6c\u573a\u52a8\u753b","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/983.html","title":{"rendered":"vue.js \u8f6c\u573a\u52a8\u753b"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

vue.js \u8f6c\u573a\u52a8\u753b<\/h1>\n<\/p><\/div>\n
\n Vue.js\u8981\u6c42\u9644\u52a0\u4e8b\u4ef6\u4fa6\u542c\u5668\uff0c\u4ee5\u4fbf\u5728\u8f6c\u573a\u7ed3\u675f\u65f6\u77e5\u9053\u5b83\u3002\u53d6\u51b3\u4e8e\u60a8\u7684
\n CSS \uff0c\u5b83\u53ef\u80fd\u662f
\n transitionend <\/strong>\u6216
\n animationend <\/strong>\u3002\u5df2\u7533\u8bf7\u3002\u5982\u679c\u4ec5\u4f7f\u7528\u7b2c\u4e00\u79cd\u7c7b\u578b\u6216\u4ec5\u4f7f\u7528\u7b2c\u4e8c\u79cd\u7c7b\u578b\uff0c\u5219Vue.js\u53ef\u4ee5\u81ea\u52a8\u68c0\u6d4b\u6b63\u786e\u7684\u7c7b\u578b\u3002\u4f46\u662f\uff0c\u5728\u5fc5\u987b\u540c\u65f6\u4f7f\u7528\u8f6c\u573a\u548c\u52a8\u753b\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u663e\u5f0f\u58f0\u660e\u7c7b\u578b\u3002\n <\/div>\n
\n \u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u5e0c\u671b\u5c06\u4e24\u8005\u90fd\u653e\u5728\u540c\u4e00\u4e2a\u5143\u7d20\u4e0a\uff0c\u4f8b\u5982\uff0c\u7531Vue.js\u89e6\u53d1\u7684CSS\u52a8\u753b\uff0c\u4ee5\u53caCSS\u8fc7\u6e21\u5bf9\u60ac\u505c\u6548\u679c\u3002\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u60a8\u5c06\u5fc5\u987b\u5728type\u5c5e\u6027\u4e2d\u660e\u786e\u58f0\u660e\u8981Vue.js\u5173\u5fc3\u7684\u7c7b\u578b\uff0c\u5176\u503c\u53ef\u4ee5\u662fanimation\u6216transition\u3002\n <\/div>\n

\u663e\u5f0f\u8fc7\u6e21\u6301\u7eed\u65f6\u95f4<\/h3>\n
\n \u8fd9\u662f
\n Vue.js \u7248\u672c2.2.0+\u4e2d\u5f15\u5165\u7684\u65b0\u529f\u80fd\u3002\u8fd9\u7528\u4e8e\u4f7f\u7528Vue.js\u5728\u5143\u7d20\u4e0a\u5e94\u7528\u8fc7\u6e21\u548c\u52a8\u753b\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cVue.js\u5fc5\u987b\u7b49\u5f85transionend\u548canimationend\u4e8b\u4ef6\uff0c\u4ee5\u68c0\u6d4b\u52a8\u753b\u6216\u8fc7\u6e21\u662f\u5426\u5b8c\u6210\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5f53\u8fc7\u6e21\u5bfc\u81f4\u5ef6\u8fdf\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u660e\u786e\u5730\u5e94\u7528\u6301\u7eed\u65f6\u95f4\uff0c\u5982\u4e0b\u6240\u793a:\n <\/div>\n
\n
 <transition :duration = \"1000\"><\/transition>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6301\u7eed\u65f6\u95f4\u5c5e\u6027\u4e0e\u8fc7\u6e21\u5143\u7d20\u4e0a\u7684: \u7b26\u53f7\u4e00\u8d77\u4f7f\u7528\uff0c\u5982\u60a8\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\u6240\u89c1\u3002\n <\/div>\n
\n \u5982\u679c\u8981\u5206\u522b\u6307\u5b9a\u7528\u4e8e\u8f93\u5165\u548c\u79bb\u5f00\u4e2a\u6848\u7684\u6301\u7eed\u65f6\u95f4\uff0c\u5219\u53ef\u4ee5\u6307\u5b9a\u5982\u4e0b:\n <\/div>\n
\n
 <transition :duration = \"{ enter: 500, leave: 800 }\">...<\/transition> 
<\/span><\/code><\/pre>\n<\/p><\/div>\n

JavaScript\u94a9\u5b50<\/h3>\n
\n \u53ef\u4ee5\u4f7f\u7528
\n JavaScript \u65b9\u6cd5\uff0c\u5c06\u8fc7\u6e21\u7c7b\u79f0\u4e3a\u65b9\u6cd5\u4e00\u4e2a\u3002\u60a8\u53ef\u4ee5\u5728\u5c5e\u6027\u4e2d\u5b9a\u4e49JavaScript\u6302\u94a9\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u4f8b\u5b50\u6765\u5f88\u597d\u5730\u7406\u89e3\u8fd9\u4e2a\u6982\u5ff5:\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span>
   <head><\/span>
      <title><\/span>Vue.js Animation<\/title><\/span>
      <link rel=\"stylesheet\" href=\"index.css\">
        <script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue\/dist\/vue.js\"><\/script><\/span>
        <script src = \"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/velocity\/1.2.3\/velocity.min.js\"><\/script><\/span>
    <\/head><\/span>
    <body><\/span>
    <div id = \"trans\">
         <button @click = \"show = !show\">
            <span style = \"font-size:25px;\">Toggle<\/span><\/span>
         <\/button><\/span>
         <transition v-on:before-enter = \"beforeEnter\"
            v-on:enter = \"enter\"
            v-on:leave = \"leave\"
            v-bind:css = \"false\">
            <p v-if = \"show\" style = \"font-size:25px;\">This is an animation Example with velocity<\/p><\/span>
         <\/transition>
      <\/div><\/span>
      <\/script><\/span>
      <script src=\"index.js\"><\/script><\/span>
   <\/body><\/span>
<\/html><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Index.js\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 var vm = new Vue({
            el: '#trans',
            data: {
               show: false
            },
            methods: {
               beforeEnter: function (el) {
                  el.style.opacity = 0
               },
               enter: function (el, done) {
                  Velocity(el, { opacity: 1, fontSize: '25px' }, { duration: 1000 })
                  Velocity(el, { fontSize: '10px' }, { complete: done })
               },
               leave: function (el, done) {
                  Velocity(el, { translateX: '15px', rotateZ: '50deg' }, { duration: 1500 })
                  Velocity(el, { rotateZ: '100deg' }, { loop: 2 })
                  Velocity(el, {
                     rotateZ: '45deg',
                     translateY: '30px',
                     translateX: '30px',
                     opacity: 0
                  }, { complete: done })
               }
            }
         })
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8ba9\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684CSS\u6587\u4ef6\u6765\u4f7f\u8f93\u51fa\u66f4\u5177\u5438\u5f15\u529b\u3002\n <\/div>\n
\n Index.css\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 html, body {
    margin: 5px;
    padding: 0;
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u7a0b\u5e8f\u6267\u884c\u540e\uff0c\u60a8\u5c06\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa:\n <\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

vue.js \u8f6c\u573a\u52a8\u753b_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\n \u5f53\u60a8\u5355\u51fb
\n \"\u5207\u6362\" <\/strong>\u6309\u94ae\u65f6\uff0c\u60a8\u4f1a\u770b\u5230\u8fc7\u6e21\u548c\u52a8\u753b\u3002\u8bf7\u53c2\u89c1\u4ee5\u4e0b\u8f93\u51fa:\n <\/div>\n

vue.js \u8f6c\u573a\u52a8\u753b_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c2\u5f20
\n

\n vue.js \u8f6c\u573a\u52a8\u753b_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c3\u5f20
\n

\n vue.js \u8f6c\u573a\u52a8\u753b_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c4\u5f20 <\/p>\n

\u793a\u4f8b\u8bf4\u660e<\/h3>\n
\n \u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff0c\u5219\u5728\u8fc7\u6e21\u5143\u7d20\u4e0a\u4f7f\u7528js\u65b9\u6cd5\u6267\u884c\u52a8\u753b\u3002\u8fc7\u6e21\u65b9\u6cd5\u7684\u5e94\u7528\u5982\u4e0b:\n <\/div>\n
\n
 <transition v-on:before-enter = \"beforeEnter\"
   v-on:enter = \"enter\"
   v-on:leave = \"leave\"
   v-bind:css = \"false\">
   <p v-if = \"show\" style = \"font-size:25px;\">Animation Example with velocity<\/p><\/span>
<\/transition>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5728\u4e8b\u4ef6\u540d\u79f0\u4e4b\u524d\u6dfb\u52a0\u524d\u7f00
\n v-on <\/strong>\u3002\u6211\u4eec\u8fd8\u5728\u8fc7\u6e21
\n v-bind: css =\"false\" <\/strong>\u4e0a\u6dfb\u52a0\u4e86\u4e00\u4e2a\u5c5e\u6027\uff0c\u4ee5\u4fbfVue.js\u5c06\u5176\u7406\u89e3\u4e3aJavaScript\u8fc7\u6e21\u3002\n <\/div>\n
\n \u65b9\u6cd5\u5728Vue.js\u5b9e\u4f8b\u5982\u4e0b:\n <\/div>\n
\n
 methods: {
   beforeEnter: function (el) {
      el.style.opacity = 0
   },
   enter: function (el, done) {
      Velocity(el, { opacity: 1, fontSize: '25px' }, { duration: 1000 })
      Velocity(el, { fontSize: '10px' }, { complete: done })
   },
   leave: function (el, done) {
      Velocity(el, { translateX: '15px', rotateZ: '50deg' }, { duration: 1500 })
      Velocity(el, { rotateZ: '100deg' }, { loop: 2 })
      Velocity(el, {
         rotateZ: '45deg',
         translateY: '30px',
         translateX: '30px',
         opacity: 0
      }, { complete: done })
   }
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6211\u4eec\u5df2\u5728\u4e0a\u8ff0\u6bcf\u79cd\u65b9\u6cd5\u4e2d\u5e94\u7528\u4e86\u6240\u9700\u7684\u8fc7\u6e21\u3002\u5355\u51fb\u6309\u94ae\u548c\u5b8c\u6210\u52a8\u753b\u540e\uff0c\u5c06\u5e94\u7528\u4e0d\u900f\u660e\u5ea6\u52a8\u753b\u3002\u7b2c\u4e09\u65b9\u5e93\u4e5f\u7528\u4e8e\u52a8\u753b\u3002\n <\/div>\n

\u5728\u521d\u59cb\u6e32\u67d3\u65f6\u8fdb\u884c\u8fc7\u6e21<\/h3>\n
\n \u5982\u679c\u8981\u5728\u5f00\u59cb\u65f6\u6dfb\u52a0\u52a8\u753b\uff0c\u5219\u5fc5\u987b\u6dfb\u52a0\"\u51fa\u73b0\"\u5c5e\u6027\u5230\u8fc7\u6e21\u5143\u7d20\u3002\u8bf7\u53c2\u9605\u4ee5\u4e0b\u793a\u4f8b\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u5b83:\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span>
   <head><\/span>
      <title><\/span>Vue.js Animation<\/title><\/span>
      <link rel=\"stylesheet\" href=\"index.css\">
      <link href = \"https:\/\/cdn.jsdelivr.net\/npm\/animate.css@3.5.1\" rel = \"stylesheet\" type = \"text\/css\">
        <script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue\/dist\/vue.js\"><\/script><\/span>
        <script src = \"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/velocity\/1.2.3\/velocity.min.js\"><\/script><\/span>
    <\/head><\/span>
    <body><\/span>
        <div id = \"trans_2\" style = \"text-align:center\">
         <transition
            appear
            appear-class = \"custom-appear-class\"
            appear-active-class = \"animated bounceIn\">
            <h3><\/span>This is BounceIn Animation Example<\/h3><\/span>
         <\/transition>
         <transition
            appear
            appear-class = \"custom-appear-class\"
            appear-active-class = \"animated swing\">
            <h3><\/span>This is Swing Animation Example<\/h3><\/span>
         <\/transition>
         <transition
            appear
            appear-class = \"custom-appear-class\"
            appear-active-class = \"animated rubberBand\">
            <h3><\/span>This is RubberBand Animation Example<\/h3><\/span>
         <\/transition>
      <\/div><\/span>
      <\/script><\/span>
      <script src=\"index.js\"><\/script><\/span>
   <\/body><\/span>
<\/html><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Index.js\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 var vm = new Vue({
            el: '#trans_2',
            data: {
               show: true
            }
         })
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u7a0b\u5e8f\u6267\u884c\u540e\uff0c\u60a8\u5c06\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa:\n <\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

vue.js \u8f6c\u573a\u52a8\u753b_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c5\u5f20 <\/p>\n


\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"vue.js \u8f6c\u573a\u52a8\u753bzh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[122],"tags":[],"class_list":["post-983","post","type-post","status-publish","format-standard","hentry","category-vuejc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/983"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=983"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/983\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}