为了账号安全,请及时绑定邮箱和手机立即绑定

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

<!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 回答

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

1 回复 有任何疑惑可以回复我~
#1

毛Bing 提问者

有区别吗?
2018-08-19 回复 有任何疑惑可以回复我~
#2

哈利法塔上的石头 回复 毛Bing 提问者

splice是一个数组方法,方法调用是fn()。你给他赋值 fn =(index, 1)是想干什么。。。
2018-08-21 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号