<template> <div> <input type="text" v-model="inputValue"> <button @click="addItem">提交</button> <ul> <li v-for="(item, index) in itemList" :key="index"> <button @click="removeItem(index)">delete</button> {{item}} </li> </ul> </div> </template> <script> export default { data () { return { inputValue: '', itemList: [] } }, methods: { addItem () { if (this.inputValue != null && this.inputValue != '') { this.itemList.push(this.inputValue) this.inputValue = '' } }, removeItem (index) { // 这里报错 this.inputValue.splice(index, 1) } } } </script> <style> </style>
这个地方写错了