vue 提交添加内容,点击删除内容

1 html

<input v-model="inputValue" />
    <button @click="handClick">提交</button>
    <ul>
        <todo-item 
        v-for="(item,index) in list" :key="index"
        :content="item"
        :index='index'
        @delete="handdelete"
        ></todo-item>
    </ul>

2 js 

export default {
        data(){
            return{
                inputValue:'',
                list:[]
            }
        },
        methods:{
        //点击提交添加内容 handClick(){
this.list.push(this.inputValue) this.inputValue='' }, // @delete="handdelete" 监听子组件的方法 delete handdelete(index){ //接收子组件传过来的index 进行删除 this.list.splice(index,1) } } }

 

相关文章:

  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
猜你喜欢
  • 2021-12-10
  • 2021-08-28
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-30
相关资源
相似解决方案