1
0

Initial commit

This commit is contained in:
Rokas Puzonas 2020-09-13 03:29:12 +03:00
commit b72179012d
13 changed files with 12149 additions and 0 deletions

2
README.md Normal file
View File

@ -0,0 +1,2 @@
# vue-todo-example
https://www.youtube.com/watch?v=Wy9q22isx3U

5
babel.config.js Normal file
View File

@ -0,0 +1,5 @@
module.exports = {
presets: [
'@vue/cli-plugin-babel/preset'
]
}

11873
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

43
package.json Normal file
View File

@ -0,0 +1,43 @@
{
"name": "vue-test",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"uuid": "^8.3.0",
"vue": "^2.6.11"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-template-compiler": "^2.6.11"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "babel-eslint"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}

BIN
public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

17
public/index.html Normal file
View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

65
src/App.vue Normal file
View File

@ -0,0 +1,65 @@
<template>
<div id="app">
<Header />
<AddTodo v-on:add-todo="addTodo" />
<Todos v-bind:todos="todos" v-on:del-todo="deleteTodo" />
</div>
</template>
<script>
import Todos from "./components/Todos"
import Header from "./components/layout/Header"
import AddTodo from "./components/AddTodo"
export default {
name: 'App',
components: {
Header,
Todos,
AddTodo
},
data() {
return {
todos: [
{ id: 1, title: "Todo One", completed:false },
{ id: 2, title: "Todo Two", completed:true },
{ id: 3, title: "Todo Three", completed:false }
]
}
},
methods: {
deleteTodo(id) {
this.todos = this.todos.filter(todo => todo.id !== id)
},
addTodo(new_todo) {
this.todos.push(new_todo)
}
}
}
</script>
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
font-family: Arial, Helvetica, sans-serif;
line-height: 1.4;
}
.btn {
display: inline-block;
border: none;
background: #555;
color: #fff;
padding: 7px 20px;
cursor: pointer;
}
.btn:hover {
background: #666;
}
</style>

BIN
src/assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1,48 @@
<template>
<div>
<form @submit="addTodo">
<input type="text" v-model="title" name="title" placeholder="Add Todo...">
<input type="submit" value="Submit" class="btn">
</form>
</div>
</template>
<script>
const uuid = require("uuid");
export default {
name: "AddTodo",
data() {
return {
title: ""
}
},
methods: {
addTodo(e) {
e.preventDefault()
const new_todo = {
id: uuid.v4(),
title: this.title,
completed: false
}
this.$emit("add-todo", new_todo)
this.title = ""
}
}
}
</script>
<style scoped>
form {
display: flex;
}
input[type="text"] {
flex: 10;
padding: 5px;
}
input[type="submit"] {
flex: 2;
}
</style>

View File

@ -0,0 +1,42 @@
<template>
<div class="todo-item" v-bind:class="{'is-complete':todo.completed}">
<p>
<input type="checkbox" v-on:change="markComplete">
{{todo.title}}
<button @click="$emit('del-todo', todo.id)" class="del">X</button>
</p>
</div>
</template>
<script>
export default {
name: "TodoItem",
props: ["todo"],
methods: {
markComplete() {
this.todo.completed = ! this.todo.completed
}
}
}
</script>
<style scoped>
.todo-item {
background: #f4f4f4;
padding: 10px;
border-bottom: 1px #ccc dotted;
}
.is-complete {
text-decoration: line-through;
}
.del {
background: #e22;
color: #fff;
border: none;
padding: 5px 9px;
border-radius: 50%;
float: right;
}
</style>

22
src/components/Todos.vue Normal file
View File

@ -0,0 +1,22 @@
<template>
<div>
<div v-bind:key="todo.id" v-for="todo in todos">
<TodoItem v-bind:todo="todo" v-on:del-todo="$emit('del-todo', todo.id)" />
</div>
</div>
</template>
<script>
import TodoItem from "./TodoItem"
export default {
name: "Todos",
props: ["todos"],
components: {
TodoItem
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,24 @@
<template>
<header class="header">
<h1>TodoList</h1>
</header>
</template>
<script>
export default {
name: "Header"
}
</script>
<style scoped>
.header {
background: #333;
color: #fff;
text-align: center;
padding: 10px;
}
.header a {
color: #fff;
padding-right: 5px;
}
</style>

8
src/main.js Normal file
View File

@ -0,0 +1,8 @@
import Vue from 'vue'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')