【问题标题】:Uncaught TypeError: Cannot read property 'push' of undefined in Vuejs未捕获的类型错误:无法读取 Vuejs 中未定义的属性“推送”
【发布时间】:2020-07-25 13:15:48
【问题描述】:

未捕获的类型错误:无法读取未定义的属性“推送”。我收到此错误。请帮我弄清楚我哪里出错了。我正在关注这个链接(https://jsbin.com/fikosoxuki/15/edit?html,js,output)

<template>
    <v-card class="mb-12">
      <v-form :model='user' class="content-padding" ref='pdfInputs'> 
       <ul>
        <li v-for="(input, index) in user.inputs">
         <input type="text" v-model="input.one"> - {{ input.one }}  
         <input type="text" v-model="input.two"> - {{ input.two }}
         <button type="button" @click="deleteRow(index)">Delete</button>
        </li>
       </ul>    
       <button type="button" @click="addRow">Add more</button>
      </v-form>
    </v-card>
</template>

<script>
 export default {
  data () {
    return {
     user: {
      inputs: []
     }
    }
  }
  methods: {
    addRow() {
      this.user.inputs.push({
        one: '',
        two: ''
      })
    },
    deleteRow(index) {
      this.user.inputs.splice(index,1)
    }
  }
 }
</script>

更新(添加错误)

【问题讨论】:

  • 你为什么不为你的代码做一个codepen链接?
  • 如果它在 jsbin 中工作,有人会如何修复它?无论如何,尝试不同的浏览器。
  • @tony19 下数据{ }
  • 数据设置在data。代码没有问题

标签: javascript vue.js vuetify.js


【解决方案1】:

我不用Vue,但是需要先新建一个Vue对象吗?

const app = new Vue({
  
  el: '#app',
  
  data: {
    user: {
      inputs: []
    }
  },
  
  methods: {
    addRow() {
      this.user.inputs.push({
        one: '',
        two: ''
      })
    },
    deleteRow(index) {
      this.user.inputs.splice(index,1)
    }
  }
  
})

export default app

【讨论】:

  • 这不是问题。我已经创建了一个 Vue 对象。它只是应用程序的页面之一。
猜你喜欢
  • 1970-01-01
  • 2017-08-12
  • 2017-07-12
  • 2020-08-23
  • 2018-10-19
  • 2015-10-20
  • 1970-01-01
  • 2016-11-22
相关资源
最近更新 更多