为什么删不了?????WTF

来源:3-4 实现todolist的删除功能

毛Bing

2018-08-19 16:27

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>todoList</title>

<style>

*{

margin: 0;

padding: 0;

font-size: 20px;

text-align: center;

}

body{

background-color: #f56;

}

#box{

margin-top: 200px;

color: white;

font-weight: 700;

}

</style>

<script src="./vue.js"></script>

</head>

<body>

<div id="box">

<input type="text" v-model="txtValue">

<input type="button" @click='handleClick' value="提交">

<ul>

<todo-item

v-for="(item,index) of list"

:key="index"

:content="item"

:index="index"

@delete="handleDelete"

></todo-item>

</ul>

</div>

<script>

//创建一个全局组件

Vue.component('todo-item',{

props:['content','index'],

template:'<li @click="handleClick">{{content}}</li>',

methods:{

handleClick:function(){

this.$emit('delete',this.index)

}

}

})



new Vue({

el:"#box",

data:{

txtValue:'',

list:[]

},

methods:{

handleClick:function(){

this.list.push(this.txtValue),

this.txtValue=''

},

handleDelete:function(index){

this.list.splice=(index,1)

}

}

})

</script>

</body>

</html>


写回答 关注

3回答

  • 水之鱼
    2018-08-19 16:46:45
    已采纳

    this.list.splice=(index,1)         =>           this.list.splice(index,1) 

    哈利法塔上的... 回复毛Bing

    splice是一个数组方法,方法调用是fn()。你给他赋值 fn =(index, 1)是想干什么。。。

    2018-08-21 22:51:55

    共 2 条回复 >

  • weixin_慕无忌5221448
    2018-11-05 16:20:27

    方法不是变量,不能加等号

  • 哈利法塔上的石头
    2018-08-21 22:52:54

    splice是一个数组方法,方法调用是fn()。你给他赋值 fn =(index, 1)是想干什么。。。

vue2.5入门

快速理解Vue编程理念上手Vue2.0开发。

147234 学习 · 675 问题

查看课程

相似问题