浏览代码

fix prop types

Evan You 9 年之前
父节点
当前提交
7ad4eb02f1

+ 23 - 5
src/platforms/web/runtime/components/transition.js

@@ -5,7 +5,17 @@ import { getRealChild } from 'core/vdom/helpers'
 
 export default {
   name: 'transition',
-  props: ['name', 'appear', 'tag', 'mode'],
+  props: {
+    name: String,
+    appear: Boolean,
+    mode: String,
+    enterClass: String,
+    leaveClass: String,
+    enterActiveClass: String,
+    leaveActiveClass: String,
+    appearClass: String,
+    appearActiveClass: String
+  },
   _abstract: true,
   render (h) {
     const children = this.$slots.default && this.$slots.default.filter(c => c.tag)
@@ -18,13 +28,21 @@ export default {
         '<transition-group> for lists.'
       )
     }
+
     const rawChild = children[0]
+
+    // if this is a component root node and the compoennt's
+    // parent container node also has transition, skip.
+    if (this.$vnode.parent && this.$vnode.parent.data.transition) {
+      return rawChild
+    }
+
     const child = getRealChild(rawChild)
     child.key = child.key || `__v${child.tag + this._uid}__`
-    ;(child.data || (child.data = {})).transition = extend(
-      { context: this },
-      this.$options.propsData
-    )
+    const data = (child.data || (child.data = {})).transition = { context: this }
+    for (const key in this.$options.propsData) {
+      data[key] = this[key]
+    }
 
     const mode = this.mode
     const oldRawChild = this._vnode

+ 3 - 9
src/platforms/web/runtime/directives/show.js

@@ -5,14 +5,15 @@ import { enter, leave } from '../modules/transition'
 
 export default {
   bind (el: HTMLElement, { value }: VNodeDirective, vnode: VNodeWithData) {
-    const transition = getTransition(vnode)
+    const transition = vnode.data.transition
+    console.log(transition)
     if (value && transition && transition.appear && !isIE9) {
       enter(vnode)
     }
     el.style.display = value ? '' : 'none'
   },
   update (el: HTMLElement, { value }: VNodeDirective, vnode: VNodeWithData) {
-    const transition = getTransition(vnode)
+    const transition = vnode.data.transition
     if (transition && !isIE9) {
       if (value) {
         enter(vnode)
@@ -27,10 +28,3 @@ export default {
     }
   }
 }
-
-function getTransition (vnode: VNodeWithData): Object | string | void {
-  const parent = vnode.parent
-  return parent && parent.data.transition != null
-    ? parent.data.transition
-    : vnode.data.transition
-}

+ 3 - 14
src/platforms/web/runtime/modules/transition.js

@@ -309,25 +309,14 @@ function once (fn: Function): Function {
   }
 }
 
-function shouldSkipTransition (vnode: VNodeWithData): boolean {
-  return !!(
-    // if this is a component root node and the compoennt's
-    // parent container node also has transition, skip.
-    (vnode.parent && vnode.parent.data.transition) ||
-    // if the element has v-show, let the runtime directive
-    // call the hooks instead
-    vnode.data.show
-  )
-}
-
-export default hasTransition ? {
+export default inBrowser ? {
   create (_: any, vnode: VNodeWithData) {
-    if (!shouldSkipTransition(vnode)) {
+    if (!vnode.data.show) {
       enter(vnode)
     }
   },
   remove (vnode: VNode, rm: Function) {
-    if (!shouldSkipTransition(vnode)) {
+    if (!vnode.data.show) {
       leave(vnode, rm)
     } else {
       rm()