[Vuejs]-Cannot read property 'property_name' of undefined

0πŸ‘

βœ…

You don’t define a row data property, but a rows data property array. Calling the selected method from inside a v-for loop will not automatically assign this.row a value.

If you want the product_id of the selected row in the selected method, pass it in the template via @change="selected(row.product_id)".

Then just reference that parameter in your selected method:

selected(id){
  console.log(id);
  axios.get('/estimate/product/' + id)
  ...
}
πŸ‘€thanksd

0πŸ‘

You seem to declare rows as an array with exactly one object in it:

    data() {
        return {
            rows: [{
                product_id: '',
                product_details: '',
                product_sellPrice: '',
            }],

But you try to access it just like a regular object:

var id = this.row.product_id;

In addition, you declare it as rows, but access it as row (missing plural s).

To get it running, first decide whether you want to name it rows or row and adapt the usage accordingly. Second, decide if rows must be an array (should it hold multiple objects?) or not.

If it should be an array, you probably want to access it like this:

var id = this.rows[0].product_id;

If it should not be an array, declare it like this:

    data() {
        return {
            rows: {
                product_id: '',
                product_details: '',
                product_sellPrice: '',      
            },
πŸ‘€cello

Leave a comment