Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v-show render的时候指令传入的是一个引用对象的话,指令不起作用。 #3

Open
czf1998 opened this issue Dec 23, 2019 · 2 comments

Comments

@czf1998
Copy link

czf1998 commented Dec 23, 2019

Version

2.6.10

Reproduction link

https://codepen.io/SamirGuo/pen/vYBezXz

Steps to reproduce

<div id="app">
<template>
  <div>
    <button @click="visible = !visible">显示/隐藏</button>
    <my-component :visible="visible" style="border-bottom: solid 1px #ccc" />
  </div>
</template>
</div>
const directive = {
    name: 'show',
    value: true
};

Vue.component('MyComponent', {
    props: {
        mystyle: '',
        visible: true
    },
    render(h) {
        directive.value = this.visible;
        return h('div', {
            // do not work!
            directives: [directive],
            // work well!
            // directives: [{
            //     name: 'show',
            //     value: this.visible
            // }],
            domProps: {
                innerText: 'sssssss'
            },
            style: this.mystyle
        });
    }
});


var Main = {
    data() {
      return { 
        visible: true
      };
    }
  };
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app')

What is expected?

v-show to be applied

What is actually happening?

v-show isn't applied


When the instruction update logic assigns oldValue, oldVnode.data.directives ["show"] and vnode.data.directives ["show"] are actually the same object.
So dir.oldValue = oldDir.value is actually equivalent to dir.oldValue = dir.value; in the later update event, dir.oldValue === dir.value

@phb1972
Copy link

phb1972 commented Dec 23, 2019

You can just spread the global object: [{...directive}],. What is the use case for a shared directive object?

@pkf1994 pkf1994 changed the title When v-show render instruction is passed a reference object, the instruction will not work v-show render的时候指令传入的是一个引用对象的话,指令不起作用。 Dec 23, 2019
@phb1972
Copy link

phb1972 commented Dec 24, 2019

Thank you. But my components are dynamically generated from a library. We are passing in data, so there is no way to deconstruct it during generation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants