Explorar o código

move v-show marker to runtime so that render functions work as expected (fix #3488)

Evan You %!s(int64=9) %!d(string=hai) anos
pai
achega
d2df58e547

+ 2 - 2
flow/vnode.js

@@ -38,7 +38,6 @@ declare interface VNodeData {
   staticClass?: string;
   class?: any;
   style?: Array<Object> | Object;
-  show?: true;
   props?: { [key: string]: any };
   attrs?: { [key: string]: string };
   domProps?: { [key: string]: any };
@@ -46,7 +45,8 @@ declare interface VNodeData {
   on?: ?{ [key: string]: Function | Array<Function> };
   nativeOn?: { [key: string]: Function | Array<Function> };
   transition?: Object;
-  transitionInjected?: boolean;
+  transitionInjected?: boolean; // marker for transition insert hook injection
+  show?: boolean; // marker for v-show
   inlineTemplate?: {
     render: Function;
     staticRenderFns: Array<Function>;

+ 0 - 5
src/compiler/codegen/index.js

@@ -130,11 +130,6 @@ function genData (el: ASTElement): string | void {
   for (let i = 0; i < dataGenFns.length; i++) {
     data += dataGenFns[i](el)
   }
-  // v-show, used to avoid transition being applied
-  // since v-show takes it over
-  if (el.attrsMap['v-show']) {
-    data += 'show:true,'
-  }
   // attributes
   if (el.attrs) {
     data += `attrs:{${genProps(el.attrs)}},`

+ 6 - 0
src/platforms/web/runtime/components/transition.js

@@ -126,6 +126,12 @@ export default {
     const oldRawChild = this._vnode
     const oldChild: any = getRealChild(oldRawChild)
 
+    // mark v-show
+    // so that the transition module can hand over the control to the directive
+    if (child.data.directives && child.data.directives.some(d => d.name === 'show')) {
+      child.data.show = true
+    }
+
     if (oldChild && oldChild.data && oldChild.key !== child.key) {
       // replace old child transition data with fresh one
       // important for dynamic transitions!

+ 1 - 1
test/unit/modules/compiler/codegen.spec.js

@@ -148,7 +148,7 @@ describe('codegen', () => {
   it('generate v-show directive', () => {
     assertCodegen(
       '<p v-show="shown">hello world</p>',
-      `with(this){return _h('p',{directives:[{name:"show",value:(shown),expression:"shown"}],show:true},["hello world"])}`
+      `with(this){return _h('p',{directives:[{name:"show",value:(shown),expression:"shown"}]},["hello world"])}`
     )
   })