inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Vue.js 중급 강좌 - 웹앱 제작으로 배워보는 Vue.js, ES6, Vuex

TodoList 컴포넌트 할 일 삭제 기능 구현

왜 저는 todoItem.item 하면 값이 안나오는걸까요?

320

el

작성한 질문수 4

1

  1. TodoList.vue코드

<template>

<div>

<ul>

<!-- <li v-for="(todoItem, index) in todoItems" v-bind:key="todoItem.item" class="shadow">

{{todoItem}}

<i class="checkBtn fa-solid fa-check" v-bind:class="{checkBtnCompleted: todoItem.completed}" v-on:click="toggleComplete(todoItem, index)"></i>

v-bind:class="{A:a}" A클래스의 a속성이 false면 안나타남, true면 나타남 -->

<!-- <span v-bind:class="{textCompleted: todoItem.completed}">

{{ todoItem.item }}

</span>

<span class="removeBtn" v-on:click="removeTodo(todoItem, index)">

<i class="fa-solid fa-trash-can"></i>

</span>

</li>> -->

<li v-for="(todoItem, index) in todoItems" v-bind:key="todoItem" class="shadow">

<i class="checkBtn fa-solid fa-check" v-bind:class="{ checkBtnCompleted: todoItem.completed }" v-on:click="toggleComplete(todoItem, index)"></i>

{{ todoItem.item }} {{ index }}

<!-- //v-bind:class="{A:a}" A클래스의 a속성이 false면 안나타남, true면 나타남 -->

<span v-bind:class="{ textCompleted: todoItem.completed }">

{{ todoItem}}

</span>

<span class="removeBtn" v-on:click="removeTodo">

<i class="fa-solid fa-trash-can"></i>

</span>

</li>

</ul>

</div>

</template>

 

<script>

export default {

data: function () {

return {

todoItems: []

}

},

methods: {

removeTodo: function (todoItem, index) {

console.log('remove items');

console.log(todoItem, index);

localStorage.removeItem(todoItem);

this.todoItems.splice(index, 1);

},

toggleComplete: function (todoItem, index) {

todoItem.completed = !todoItem.completed;

console.log(index);

console.log(todoItem.item);

//로컬스토리지 갱신

localStorage.removeItem(todoItem.item);

localStorage.setItem(todoItem.item, JSON.stringify(todoItem));

}

},

created: function () {

if (localStorage.length > 0) {

for (var i = 0; i < localStorage.length; i++) {

if (localStorage.key(i) !== 'loglevel:webpack-dev-server') {

console.log(JSON.parse(localStorage.getItem(localStorage.key(i))));

this.todoItems.push(localStorage.key(i));

}

}

}

}

}

</script>

 

<style scoped>

ul {

list-style-type: none;

padding-left: 0px;

margin-top: 0;

text-align: left;

}

li {

display: flex;

min-height: 50px;

height: 50px;

line-height: 50px;

margin: 0.5rem 0;

padding: 0 0.9rem;

background: white;

border-radius: 5px;

}

.removeBtn {

margin-left: auto;

color: #de4343;

}

.checkBtn {

line-height: 45px;

color: #62acde;

margin-right: 5px;

}

.checkBtnCompleted {

color: #b3adad;

}

.textCompleted {

text-decoration: line-through;

color: #b3adad;

}

</style>

 

  1. TodoInput.vue코드

    <template>

    <div class="inputBox shadow">

    <input type= "text" v-model="todoItems" v-on:keyup.enter="addTodo">

    <span class="addContainer" v-on:click="addTodo">

    <i class="fas fa-plus addBBtn"></i>

    </span>

    </div>

    </template>

    <script>

    export default {

    data: function(){

    return{

    todoItems: ""

    }

    },

    methods:{

    addTodo: function(){

    if(this.todoItems !== ''){ //저장하는 로직

    //localStorage.setItem(key, value);

    //localStorage.setItem(this.newTodoItem, this.newTodoItem);

    var obj = {completed: false, item: this.todoItems};

    //localStorage.setItem(this.newTodoItem,obj);

    localStorage.setItem(this.todoItems, JSON.stringify(obj)); //obj 객체 > string화

    this.clearInput();

    }

    },

    clearInput: function(){

    this.todoItems = '';

    }

    }

    }

    </script>

    <style scoped>

    input:focus{

    outline: none;

    }

    .inputBox {

    background: white;

    height: 50px;

    line-height: 50px;

    border-radius: 5px;

    }

    .inputBox input {

    border-style: none;

    font-size: 0.9rem;

    }

    .addContainer {

    float: right;

    background: linear-gradient(to right, #6478FB, #8763FB);

    display: block;

    width: 3rem;

    border-radius: 0 5px 5px 0;

    }

    .addBtn {

    color: white;

    vertical-align: middle;

    }

    </style>

javascript vue.js es6 vuex

답변 1

0

캡틴판교

안녕하세요, 첨부해 주신 코드 내용을 보기가 어렵네요.. 강의 내용과 리포의 코드를 다시 한번 확인해 보시겠어요? :)

Chrome 개발자 모드 확장이 안됨

0

268

1

깃 권한 요청드립니다

0

118

1

vue.js 중급 리포지토리 권한 관련

0

118

1

vuex + axios 질문 있습니다!

1

198

2

깃 권한 요청드립니다!

0

161

1

강의 깃주소 문의

0

145

1

router-view에 props를 어떻게 넘길 수 있나요?

1

281

2

Vue가 인식되지 않는 현상

0

207

1

기초강좌는 어디있나요?

1

191

2

App.vue가 필요한 이유

0

193

1

getter가 정의되어 있지 않아 오류가 발생합니다.

1

254

1

뷰 라이프사이클

1

188

1

TSLint 말고 TSLint Vue 설치해도 되나요?

1

368

3

로컬 스토리지는 어디에 있나요?

1

282

1

vuex 실행시 새로고침해야지만 리스트에 나타나는 현상

1

389

2

export default 관련한 질문

0

354

2

깃허브 vue-todo 접근불가에 따른 확인요청

1

354

2

깃허브에 문제있는것 같습니다.

1

274

2

인프런 강의 재생 화면 구성 변경 문의드립니다

1

306

2

addTodo Helper 함수 적용

1

243

1

vuex 헬퍼 전역 설정

1

248

2

github 권한요청드립니다.

1

258

2

이벤트 위치에 대한 궁금증 입니다.

1

224

2

구조 차이에 대한 문의

1

346

2