1.错误做法,添加进的所有数据会一模一样
- <input v-model="newItem.question"/>
- data () {
- return {
- questionlist: [],
- newItem: {
- question: '',
- items: ['不愿意参加', '配合参加', '即使只要']
- }
- }
- }
- methods: {
- add () {
- this.questionlist.push(this.newItem)
- }
- }
2.正确做法
- <input v-model="newQuestion"/>
- data () {
- return {
- questionlist: [],
- newQuestion: '',
- newItems: ['不愿意参加', '配合参加', '即使只要']
- }
- }
- add () {
- var obj = {}
- obj.question = this.newQuestion
- obj.items = this.newItems
- this.questionlist.push(obj)
- }