반응형

index.html



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>kkwproject</title>
    <!-- Latest compiled and minified CSS -->
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
 
  </head>
  <body>
    <div class="container">
      <div id="app"></div>
    </div>
    <!-- built files will be auto injected -->
  </body>
 
  <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <!-- Latest compiled and minified JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</html>
 
cs



main.js



1
2
3
4
5
6
7
8
9
10
11
12
13
14
import Vue from 'vue'
import App from './App'
import router from './router'
 
Vue.config.productionTip = false
 
/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
 
cs



App.vue


1
2
3
4
5
6
7
8
9
10
11
12
13
 
<template>
  <div id="app">
    <img src="./assets/logo.png">
    <router-view/>
  </div>
</template>
 
<script>
export default {
  name'App'
}
</script>
cs



router의 index.js


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
import Vue from 'vue'
import Router from 'vue-router'
import TodoPage from '@/components/TodoPage'
 
Vue.use(Router)
 
export default new Router({
  routes: [
    {
      path: '/',
      name'TodoPage',
      component: TodoPage
    }
  ]
})
 
cs




components의 TodoPage.vue


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<template>
    <div class="container">
        <h2> Todo List </h2>
        <div class ="input-group" style="margin-bottom:10px;">
            <input type="text" class="form-control" placeholder="할일을 입력하세요" v-model="str" @keyup.enter ="createTodo(str)">
            <span class="input-group-btn">
                <button class="btn btn-default" type="button" @click="createTodo(str)"> 추가 </button>
            </span>
        </div>
        <ul class="list-group">
            <li class="list-group-item" v-for="(todo, index) in todos">
                {{ todo.name }}
                <div class="btn-group pull-right" style="font-size: 12px; line-height: 1;">
                    <button type="button" class="btn-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        더보기 <span class="caret"></span>
                    </button>
                    <ul class="dropdown-menu">
                        <li><a href="#" @click="deleteTodo(index)"> 삭제 </a></li>
                    </ul>
                </div>
            </li>
        </ul>
    </div>
</template>
 
<script>
    export default {
        name'TodoPage',
        data(){ 
            return {
            str:null,
            todos: [
                {
                    name'밥 먹기'
                },
                {
                    name'공부 하기'
                },
                {
                    name'일하기'
                },
            ],
            }
        },
 
        methods:{
            deleteTodo:function(index){
                this.todos.splice(index,1);
            },
 
            createTodo:function(val){
                this.todos.push({name: val});
                
            },
        },
 
    }
    
</script>
cs



todo list를 구현하여 엔터 혹은 추가 버튼을 이용하여 추가할 수 있고


더보기 버튼을 이용하여 삭제 버튼을 구현 할 수 있다.


자세한 사항은 코드를 통해 확인하자.


이제 이 내용을 통해 다음 게시물에 나올 admin 페이지를 한번 구현 해보자.







반응형