最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Error [Vue warn]: v-bind without argument expects an Object or Array value - Stack Overflow

programmeradmin2浏览0评论

Every time I toggle show to true I get error warning:

Error [Vue warn]: v-bind without argument expects an Object or Array value

The Test ponent does not get correct value for show passed to it as it is always false.

My question is: how can I get rid of the warning and have VUE do what I expect it to do (toggle show and pass it to test when test emits toggle-filter)

const Filter = Vueponent('Test', {
  template: `<div>
    {{show?'true':'false'}}
    <button v-on:click="toggleFilter">toggle</button>
  </div>`,
  props: ['show'],
  methods: {
    toggleFilter(e) {
      this.$emit('toggle-filter', e);
    },
  },
});

const app = new Vue({
  el: '#app',
  //ponents: {Filter},
  data: {
    show: false,
  },
  methods: {
    toggleFilter() {
      this.show = !this.show;
      console.log('show:',this.show);
    },
  },
});
<script src=".5.17/vue.js"></script>
<div id="app">
  <div>
    <Test v-bind.show="show" v-on:toggle-filter="toggleFilter"></Test>
    {{show?'true':'false'}}
  </div>
</div>

Every time I toggle show to true I get error warning:

Error [Vue warn]: v-bind without argument expects an Object or Array value

The Test ponent does not get correct value for show passed to it as it is always false.

My question is: how can I get rid of the warning and have VUE do what I expect it to do (toggle show and pass it to test when test emits toggle-filter)

const Filter = Vue.ponent('Test', {
  template: `<div>
    {{show?'true':'false'}}
    <button v-on:click="toggleFilter">toggle</button>
  </div>`,
  props: ['show'],
  methods: {
    toggleFilter(e) {
      this.$emit('toggle-filter', e);
    },
  },
});

const app = new Vue({
  el: '#app',
  //ponents: {Filter},
  data: {
    show: false,
  },
  methods: {
    toggleFilter() {
      this.show = !this.show;
      console.log('show:',this.show);
    },
  },
});
<script src="https://cdnjs.cloudflare./ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div>
    <Test v-bind.show="show" v-on:toggle-filter="toggleFilter"></Test>
    {{show?'true':'false'}}
  </div>
</div>

Share Improve this question edited Mar 24, 2020 at 9:40 HMR asked Mar 24, 2020 at 9:32 HMRHMR 39.4k25 gold badges98 silver badges174 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You should have v-bind:show instead of v-bind.show.

发布评论

评论列表(0)

  1. 暂无评论