본문 바로가기
보드게임 긱 추천 게임
Wizard Thumbnail
BoardGameGeek 사이트에서 인기순위 상위 100개 중 랜덤 3개를 보여줍니다.
BGG
귀펀치토끼는 부서지지 않는다.
주소(D)
영웅은 공부 따원 안 한다네/뷰

[Vue.js] 삭제기능구현

 

App.vue

        <ul>
          <todo-list-item
            v-for="(todoItem, index) in todoItems"
            :key="index"
            :index="index"
            :todoItem="todoItem"
            @remove="removeTodoItem"
          ></todo-list-item>
        </ul>
        
      removeTodoItem(index: number) {
      console.log("삭제할 인덱스 ==========>", index);
      this.todoItems.splice(index, 1);
      storage.save(this.todoItems);
    },

TodoItemList.vue

<template>
  <div>
    <li>{{ todoItem }} <button @click="removeTodoItem">삭제</button></li>
  </div>
</template>

<script lang="ts">
import Vue from "vue";

export default Vue.extend({
  props: {
    todoItem: String,
    index: Number,
  },
  methods: {
    removeTodoItem() {
      console.log("삭제버튼 눌러떠요");
      this.$emit("remove", this.index);
    },
  },
});
</script>

<style scoped></style>

 

 

완료
내 컴퓨터