new Vue({
el: "#app",
data(){
return{
content: "",
isEditingIndex: null
}
},
props:{
Items:{
type:Array,
default: () => [{Item:1},{Item:2}]
},
itemIndex:{
type: Number,
default: 1
}
},
methods:{
removeItem: function(idx){
this.Index = idx;
this.$emit('remove', this.Index);
},
itemContentChange(e){
this.content = e.target.value;
},
}
})
.itemSection{
background-color: rgb(0, 0, 0);
margin-left: 25px;
width: 200px;
float: left;
margin-bottom: 5px;
border-radius: 5px;
border-width: 1px;
border-style: solid;
min-height: 40px;
color: white;
text-align: center;
display: flex;
}
.removeItem{
color: white;
}
.listItems{
align-items: center;
z-index: absolute;
display: flex;
}
.OptionMainSection{
width: 20%;
right: 0;
}
.ItemSection{
height:100%;
position:relative;
}
.ItemTitleList{
width: 80%;
}
.OptionMainSection{
display: flex;
flex-direction: column;
}
.OptionMainSection p{
margin: 0;
line-height: 25px;
cursor: pointer;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9MTIkjHinKOEG73Inks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgelOsdf==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<section v-if="Items.length > 0" class="mainItemSection">
<section v-for="(items, index) in Items" :key="index" class="itemSection" >
<!-- 👇 check for index -->
<div class="ItemTitleList" v-if="isEditing !== index">
<div class="ItemSection">
<p class="listItems">{{ items.Item }}</p>
</div>
</div>
<div class="ItemTitleList" v-else>
<div class="ItemSection">
<input :value="content" @change="itemContentChange" type="text" class="input-item"/>
</div>
</div>
<div class="OptionMainSection">
<div class="OptionMainSection">
<p class="removeItem fa fa-close" @click="removeItem(index)"></p>
<!-- 👇 set index -->
<p class="editItem fa fa-edit" @click="isEditing = index"></p>
</div>
</div>
</section>
</section>
</div>