2

I have a Vue component that expects a property of type Array and I am passing an array while using the component. But I am still getting this warning.

[Vue warn]: Invalid prop: type check failed for prop "columns". Expected , got Array.

However the component is working fine and values in columns property are showing as expected.

Update Here's what I am doing

Parent Component

<template>
  <section class="content">
    <div class="row center-block">
      <!-- <h2>Data tables</h2> -->
      <div class="col-md-12">
        <div class="box box-success">
          <!-- <div class="box-header">
            <h3 class="box-title">Data Table With Full Features</h3>
          </div> -->
          <!-- /.box-header -->
          <div class="box-body">

            <datatable :columns="columns" :url="ajax_url"></datatable>

            <!-- /.box-body -->
          </div>
        </div>
      </div>
    </div>
  </section>
</template>


<script>
import datatable from "../partials/datatable"

export default {
  name: 'SubscriberListIndex',
  components: { datatable },
  data () {
    return {
      columns: [
        {label: '#', data: 'id', searchable: true},
        {label: 'List Name', data: 'name', searchable: true},
        {label: 'Type', data: 'type', searchable: true},
        {label: 'Created On', data: 'created_at', searchable: true},
        {
          label: 'Actions',
          data: 'id',
          renderAs: function(ListId) {
            return `<a href="/subscriber-lists/${ListId}" class="btn btn-info btn-xs">edit</a>`
          }
        }
      ],
      ajax_url: '/datatables/subscriber-lists'
    }
  },
  methods: {

  },
  mounted() {

  }
}
</script>
<style>
</style>

datatable component

<template>

<script>

export default {
  name: 'DataTable',
  data () {
    return {
    }
  },
  computed: {
  },
  props: {
    columns: [],
    url: ''
  },
  methods: {
  },
  mounted() {
  }
}
</script>

<style>
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}
</style>
4
  • Can you show any code related to this Commented Jan 24, 2019 at 7:50
  • @ljubadr I have updated the question. I have created component "datatable" and passing "columns" variable of parent component to this component Commented Jan 24, 2019 at 8:09
  • Show also your code for datatable component. Commented Jan 24, 2019 at 8:14
  • Or at least how you define props columns Commented Jan 24, 2019 at 8:17

1 Answer 1

4

You need to define props data type in datatable component

props: {
  columns: {
    type: Array,
    default: []
  }
}
Sign up to request clarification or add additional context in comments.

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.