第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

使用了組件后做的todolist再怎么實(shí)現(xiàn)刪除每項(xiàng)功能呢?

https://img1.sycdn.imooc.com//5b5ebf0400019dc404040151.jpghttps://img1.sycdn.imooc.com//5b5ebf8a0001017e09870769.jpg

這個(gè)是通過拆分組件寫的todolist,我想點(diǎn)擊刪除按鈕但是沒有到達(dá)刪除的效果,是為啥呢?

正在回答

4 回答

子組件沒有定義handleDelete方法。

父組件使用 props 把數(shù)據(jù)傳給子組件。

子組件使用 $emit 觸發(fā)父組件的自定義事件。自定義事件調(diào)用父組件的方法刪除list中的一個(gè)元素。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕粉3727899 提問者

非常感謝!
2018-07-31 回復(fù) 有任何疑惑可以回復(fù)我~

<body>


????<div?id="root">

????????<div>

????????????<input?v-model="inputValue"/>

????????????<button?@click="handleClick">提交</button>

????????</div>

????????<ul>

????????????<todo-item

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

????????????????:key="index"

????????????????:content=item

????????????????:mark="index"

????????????????@delete-list="deleteList($event)">

????????????</todo-item>

????????</ul>

????</div>

????<script>

????????//?全局組件

????????Vue.component("todo-item",{

????????????props:?["content",?"mark"],?//接受外部傳入的content屬性的值

????????????template:?"<li?@click='handleDelete()'>{{content}}-X</li>",

????????????data:?function(){

????????????????return?{

????????????????????myindex:?this.mark

????????????????}

????????????},

????????????methods:?{

????????????????handleDelete:?function(){

????????????????????//?自定事件,通知父組件

????????????????????//?console.log(this.mylist)

????????????????????//?console.log(this.myindex)

????????????????????this.$emit("delete-list",?this.myindex)

????????????????}

????????????}

????????}),


????????//?局部組件

????????//?var?TodoItem?=?{

????????//?????template:?"<li>item</li>"

????????//?}


????????new?Vue({

????????????el:?"#root",

????????????//?注冊(cè)局部組件

????????????//?components:?{

????????????//?????"todo-item":?TodoItem

????????????//?},

????????????data:?{

????????????????list:?[],

????????????????inputValue:?''

????????????},

????????????methods:?{

????????????????handleClick:?function(){

????????????????????this.list.push(this.inputValue)

????????????????????this.inputValue=''

????????????????},

????????????????deleteList:?function(para){

????????????????????console.log("父組件的刪除")

????????????????????console.log(para)

????????????????????//?alert(para)

????????????????????this.list.splice(para,?1)

????????????????}

????????????}

????????})

????</script>


</body>



0 回復(fù) 有任何疑惑可以回復(fù)我~

<!DOCTYPE html>

<html>

<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>Document</title>

</head>

<body>

<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>


<div id="app">

<input type="text" v-model="value" />?

<button @click="pull">增加</button>

<button @click="move">刪除</button>

<ol>

<!--<li v-for="(item,index) of list" :key='index'>{{item}}</li>-->

<!--index 角標(biāo)-->

<kkk v-for="(item,index) of list" :key='index' :content='item'></kkk>

</ol>


</div>


<script>

//全局組件

Vue.component('kkk',{

props:['content'],

template:'<li>{{content}}</li>'

})


//局部組件

// var itn=Vue.component('kkk',{

// props:['content']

// template:'<li>{{content}}</li>'

// })


new Vue({


el:'#app',

data:{

value:'',

list:[],

},

methods:{

pull:function(){


this.list.push(this.value);

this.value='';

},

move:function(){

this.list.shift();

}

}


})




</script>



</body>

</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~
//?把handleClick方法定義在子組件內(nèi)
<!doctype?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>Document</title>
????<script?src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script>
</head>
<body>
<div?id="root">
????<div>
????????<input?v-model="inputValue"/>
????????<button?@click="handleClick">提交</button>
????</div>
????<ul>
????????<todo-item?v-for="(item,?index)?of?list"?:key="index"?:content="item"?:origin_list="list"></todo-item>
????</ul>
</div>

<script>
????Vue.component('todo-item',?{
????????props:?['content',?'origin_list'],
?template:?"<li?>{{content}}<p?@click='handleClick'>X</p></li>",
?methods:?{
????????????handleClick:?function?()?{
????????????????this.origin_list.pop(this.item);
????????????}
????????}
????});
????new?Vue({
????????el:?'#root',
?data:?{
????????????list:?[],
?inputValue:?'',
?},
?methods:?{
????????????handleClick:?function?()?{
????????????????if?(this.inputValue)?{
????????????????????this.list.push(this.inputValue);
????????????????????this.inputValue?=?'';
????????????????}
????????????}
????????}
????})
</script>

</body>
</html>


0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

使用了組件后做的todolist再怎么實(shí)現(xiàn)刪除每項(xiàng)功能呢?

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)