babel-plugin-transform-vue-jsx icon indicating copy to clipboard operation
babel-plugin-transform-vue-jsx copied to clipboard

v-show not working when toggle bind value

Open mu-yu opened this issue 7 years ago • 9 comments

v-show works fine with initialize value,but if I changed the value in the future, the element won't toggle visible status.

here is my example code:

<el-input v-show={this.tableFilterVisible} class="custom-th-filter"
              placeholder="输入以筛选"
              value={this.queryForm.appName}
              onInput={(appName: string) => {this.queryForm.appName = appName}}
              onChange={this.initQuery} >
</el-input>

mu-yu avatar Dec 28 '17 09:12 mu-yu

V-show works fine when I try it, looks like your component (<el-input />) simply does not support that. Can you please provide a reproduction?

nickmessing avatar Jan 14 '18 15:01 nickmessing

Thank you for you response. I have uploaded a project here to reproduce the issue here: https://github.com/mu-yu/questions/tree/master/vueTsxIssue

run npm run dev and click toggle button, and you will see the el-input element in column2 and column3 won't change.

mu-yu avatar Jan 15 '18 06:01 mu-yu

@mu-yu, thank you, will check as soon as I have some time

nickmessing avatar Jan 15 '18 17:01 nickmessing

I am actually having the same or very similar problem. I have a v-show (although the same happens with v-if) binded to a value that changes later on from false to true, however it does not react after the change. I will try to create a minimal reproducible test case.

manast avatar Jan 26 '18 11:01 manast

I think my problem is wrong this in class. I have noticed this(https://github.com/vuejs/vue-class-component#this-value-in-property) some days ago, which may be helpful to you.@manast

mu-yu avatar Jan 29 '18 02:01 mu-yu

I have encountered this situation; Did you put the v-show in the root element of the component?

hou-pu avatar Mar 01 '18 08:03 hou-pu

I also get this behavior. For me, it appears to be related to trying to pass in the argument to toggle it.

This does not work Toggle: function (target) { target = !target; }

This works Toggle: function () { this.showAllSocialNetworkData = !this.showAllSocialNetworkData; }

oslotboom avatar Jun 04 '18 22:06 oslotboom

<div id="app">
  <template v-show="show">
    <h1>template v-show: {{ show }}</h1>
    <p>What the head</p>
  </template>
  
  <template v-if="show">
    <h1>template v-if: {{ show }}</h1>
    <p>What the head</p>
  </template>
  
  <div v-show="show">
    <h1>div v-show: {{ show }}</h1>
    <p>What the head</p>
  </div>
  
  <div v-if="show">
    <h1>div v-if: {{ show }}</h1>
    <p>What the head</p>
  </div>
  
  <button @click="change()">click</button>
</div>
new Vue({
  el: '#app',
  data: {
    show: false
  },
  methods: {
    change() {
      this.show = !this.show
      console.log(this.show)
    }
  }
})

I have same behavior which v-show work with a div but not with a template https://codepen.io/kanyu/pen/QoRxLY?editors=1111

kanyu avatar Mar 27 '19 07:03 kanyu

@kanyu v-show does not work with <template>.

See docs: https://vuejs.org/v2/guide/conditional.html#v-show

simshaun avatar Apr 16 '19 02:04 simshaun