亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

如果不使用組件的話可不可以實現這個功能??自己嘗試了一下發現不知道如何獲取當前點擊的<li>標簽的索引。

<!DOCTYPE html>

<html lang="zh-CN">

<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">

<link rel="stylesheet" href="./reset.css">

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

<title>Document</title>

</head>

<body>

<div id='root'>

<input v-model='inputValue'/>

<button @click='handleAdd'>添加</button>

<ul>

<li v-for="(item, index) in list" :key='index' :index="index" @click='handleDelete(index)'>{{item}}下標{{index}}</ul>

</ul>

</div>

</body>

<script>

new Vue({

el: '#root',

data: {

inputValue:'',

list:[]

},

methods: {

handleAdd: function() {

this.list.push(this.inputValue)

this.inputValue=''

},

handleDelete: function(e) {

this.list.splice(e.target,1)

}

}

})

</script>

</html>


正在回答

2 回答

你的<li>標簽后面是</ul>

delete參數直接用index就可以取到的

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

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Document</title>

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

</head>

<body>

<div id="root">

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

<button @click="inputSubmit">提交</button>

<ul>

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

@click="remove(index)">{{item}}下標{{index}}</li>

</ul>

</div>


<script>

new Vue({

el:"#root",

data:{

inputValue:'',

list:[]

},

methods:{

inputSubmit:function(){

this.list.push(this.inputValue);

this.inputValue=""

},

remove:function(index){

this.list.splice(index,1)

}

}

})

</script>

</body>

</html>

你的太亂了,我自己寫了一個,你看一下

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

舉報

0/150
提交
取消

如果不使用組件的話可不可以實現這個功能??自己嘗試了一下發現不知道如何獲取當前點擊的<li>標簽的索引。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號