-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.vue
141 lines (118 loc) · 2.79 KB
/
app.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<script setup>
import { ref, computed, reactive } from 'vue'
const msg = ref('Hello World!')
const state = reactive({count:0})
const characterCount = ()=>{
return newItem.value.length
}
const reversedItems = computed(()=> [...items.value].reverse())
const items = ref([])
const ids = ref(0)
const newItem = ref('')
const nb = ref()
const urgent = ref(false)
const addItem = ()=>{
if(newItem.value){
items.value.push({idActive: ids.value,label: newItem.value, number: nb.value,active: false, purchased: false, highPriority: urgent.value})
nb.value = ''
newItem.value = ''
urgent.value = false
ids.value++
}
}
const cancel = (itemId)=>{
for (let i=0;i< items.value.length;i++){
if(itemId === items.value[i].idActive){
items.value.splice(i,1)
}
}
}
function showDelete(){
this.items.value.active = !this.items.value.active
}
const togglePurchased = (item) =>{
item.purchased = !item.purchased
}
// ids.value = items.value[items.value.length - 1].id +1
</script>
<template>
<h1>{{ msg }}</h1>
<div class="inputItem">
<input type="number" v-model="nb" placeholder="How many" />
<input type="text" v-model="newItem" v-on:keyup.="" placeholder="Add an item" />
<div class="checkUrgent">
<input type="checkbox" v-model="urgent" @:click="" />
<label>Urgent</label>
</div>
<button v-bind:disabled="!newItem" v-on:click="addItem">Add item</button>
<p class="counter">{{characterCount()}}/200</p>
</div>
<ul>
<li
v-for="({idActive, label, number,active, purchased, highPriority},index) in reversedItems"
:key="items.id"
@mouseup="showDelete"
class="static-class"
:class="[
purchased ? 'strikeout text-gray': 'underlined',
highPriority ? 'priority': ''
]"
@click="togglePurchased(items[index])"
>
{{number +' '+ label}}
<button v-show="active" @click="cancel(idActive)" class="deleteBtn"> X</button>
</li>
</ul>
<p v-if="!items.length">Nothing to see here</p>
</template>
<style>
ul{
list-style: none;
padding: 0;
cursor: pointer;
}
body{
position: absolute;
top: 30%;
left: 15%;
width: 400px;
height: auto;
background-color: #ffffff;
padding: 20px 40px;
box-shadow: 0 1px 8px 0px rgb(2, 0, 0,0.2);
border-radius: 10px;
display: flex;
flex-direction: column;
gap: 20px;
}
.inputItem{
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 10px;
}
.deleteBtn{
background: transparent;
border: none;
cursor: pointer;
color: red;
font-weight: bold;
font-size: 19px;
}
.strikeout{
text-decoration-line: line-through;
}
.priority{
font-weight: 600;
color: orange;
}
.text-gray{
color: #818181;
}
.counter{
margin-top: 0px;
margin-left: 10px;
font-size: 14px;
color: lightslategray;
}
</style>