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

為了賬號安全,請及時綁定郵箱和手機立即綁定

todolist刪除沒反應(yīng)也沒報錯,求大家?guī)兔纯?/h1>
<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>vue中組件與實例的關(guān)系</title>
????<script?src="./vue.js"></script>
</head>
<body>
<div?id="root">
????<div>
????????<input?v-model="inputValue"?/>
????????<button?@click="handleSubmit">提交</button>
????</div>
????<ul>
????????<todo-item?v-for="(item,index)?of?list"
?:key="index"
?:content="item"
?:index="index"
?@click="handleDelete"
?>
????????</todo-item>
????</ul>

</div>

<script>
?//全局組件?(vue中組件與實例的關(guān)系:vue的每一個組件都是vue的實例);
?Vue.component('todo-item',{
????????props:['content','index'],//從副組件中接收content數(shù)據(jù)和index下標(biāo)
?template:'<li>{{content}}?{{index}}</li>',
?methods:{
????????????handleClick:function(){
???????????????this.$emit('delete',this.index)
????????????},
?}
????});
?new?Vue({
????????el:"#root",
?data:{
????????????inputValue:'',
?list:[]
????????},
?methods:{
????????????handleSubmit:function?()?{
????????????????this.list.push(this.inputValue)
????????????????this.inputValue?=?''
?},
?handleDelete:function?()?{
????????????????alert(11);
?}
????????}

????});
</script>
</body>
</html>


正在回答

7 回答

template:'<li>{{content}}?{{index}}</li>',

在這里,你沒有綁定事件

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

http://img1.sycdn.imooc.com//5f12d7dc0001f1af06570261.jpg

這個地方少了監(jiān)聽事件 正確應(yīng)該為?

<li?@click="handleClick()">{{content}}?{{index}}</li>


0 回復(fù) 有任何疑惑可以回復(fù)我~
  1. <todo-item>中應(yīng)該是@delete而不是click

  2. template中的li沒有增加點擊事件@click="handleClick"

    增加以上兩個,點擊后會彈出對應(yīng)的內(nèi)容

  3. 如果需要刪除:

    handleDelete: function (index) {

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

    }


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

自組件中,沒有@click觸發(fā)你的handleClick方法


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

除了@delete, handledelete方法寫的也不對啊?handleDelete:function?(index)?{
????????????????this.list.spilice(index,1);
?}

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

一樣的,不過還是謝謝啦

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

言丶葉

不一樣的,父組件要監(jiān)聽子組件對外發(fā)布的delete事件,你寫成click就不對了。你要監(jiān)聽的是子組件的click事件,不是父組件。
2019-10-31 回復(fù) 有任何疑惑可以回復(fù)我~

父組件監(jiān)聽delete方法的那個你寫的@click應(yīng)該不對吧,不是應(yīng)該是@delete嗎?

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

舉報

0/150
提交
取消

todolist刪除沒反應(yīng)也沒報錯,求大家?guī)兔纯?/h1> 我要回答 關(guān)注問題

微信客服

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

幫助反饋 APP下載

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

公眾號

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