1

I'm new to vue.js. I have a table generated with bootstrap-vue and I want to have filter in individual column. I followed this answer "Bootstrap-vue b-table with filter in header". But I got "Uncaught ReferenceError: Vue is not defined" in console and I got "the template root disallows 'v-for' directives ". I'm unable to solve it.

Please help me.

<div id="app">
<b-table striped show-empty :items="filtered">
  <template slot="top-row" slot-scope="{ fields }">
    <td v-for="field in fields" :key="field.key">
      <input v-model="filters[field.key]" :placeholder="field.label">
    </td>
  </template>
</b-table>
</div>
<script>

  new Vue({
  el: '#app',
  data: {
    filters: {
      id: '',
      issuedBy: '',
      issuedTo: ''
    },
    items: [{id:1234,issuedBy:'Operator',issuedTo:'abcd-efgh'},{id:5678,issuedBy:'User',issuedTo:'ijkl-mnop'}]
  },
  computed: {
    filtered () {
      const filtered = this.items.filter(item => {
        return Object.keys(this.filters).every(key =>
            String(item[key]).includes(this.filters[key]))
      })
      return filtered.length > 0 ? filtered : [{
        id: '',
        issuedBy: '',
        issuedTo: ''
      }]
    }
  }
})

</script>

2 Answers 2

0

It would be better to know how the Vue library is imported but for the reference error please make sure the Vue library script tag is inserted before the file you displayed and before including vue-boostrap.

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

1 Comment

It's not working. I'm leaning vue js. I tried to implement this by installing project from scratch. I made few pages but when i run the vue pages on browser, it displays blank page. So i downloaded the project from github(Link=bezkoder.com/jwt-vue-vuex-authentication) and I tried this code on that downloaded project but it doesnot work. Please help me. @Nicolas Brondin-Bernard
0

Vue declaration is missing You have to add this script after /div

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

Comments

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.