4

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 component 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.component('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',
  //components: {Filter},
  data: {
    show: false,
  },
  methods: {
    toggleFilter() {
      this.show = !this.show;
      console.log('show:',this.show);
    },
  },
});
<script src="https://cdnjs.cloudflare.com/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>

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

3 Comments

That's it, thank you. Do you know if there are any dev tools/plugins for vscode that allow me to create vue code without having to guess what the syntax is and letting it spit out unhelpful errors during runtime?
I installed that but doesn't do anything for .html files (it doesn't know they are templates), my vue files look like <template src="./template.html"></template>
Thank you! This should be accepted as the answer! :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.