Skip to content

Commit 5f9bea6

Browse files
committed
refactor: 重构
1 parent 70fe41e commit 5f9bea6

File tree

10 files changed

+50
-105
lines changed

10 files changed

+50
-105
lines changed

src/views/Day32_GoodCheapFast/Index.vue

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,39 @@
11
<script setup>
2-
import { ref } from 'vue'
3-
4-
const good = ref(false)
5-
const cheap = ref(false)
6-
const fast = ref(false)
2+
const typeOption = reactive({
3+
good: false,
4+
cheap: false,
5+
fast: false,
6+
})
77
function handleChange(flag) {
8-
if (good.value && cheap.value && fast.value) {
8+
if (typeOption.good && typeOption.cheap && typeOption.fast) {
99
if (flag === 'good')
10-
fast.value = false
10+
typeOption.fast = false
1111
1212
if (flag === 'cheap')
13-
good.value = false
13+
typeOption.good = false
1414
1515
if (flag === 'fast')
16-
cheap.value = false
16+
typeOption.cheap = false
1717
}
1818
}
1919
</script>
2020

2121
<template>
22-
<div class="body">
22+
<div class="body base_container">
2323
<h2>How do you want your project to be?</h2>
2424

25-
<div class="toggle-container">
26-
<input
27-
id="good"
28-
v-model="good"
29-
type="checkbox"
30-
class="toggle"
31-
@change="handleChange('good')"
32-
>
33-
<label for="good" class="label">
34-
<div class="ball" />
35-
</label>
36-
<span>Good</span>
37-
</div>
38-
39-
<div class="toggle-container">
40-
<input
41-
id="cheap"
42-
v-model="cheap"
43-
type="checkbox"
44-
class="toggle"
45-
@change="handleChange('cheap')"
46-
>
47-
<label for="cheap" class="label">
48-
<div class="ball" />
49-
</label>
50-
<span>Cheap</span>
51-
</div>
52-
53-
<div class="toggle-container">
25+
<div v-for="key in Object.keys(typeOption)" :key class="toggle-container">
5426
<input
55-
id="fast"
56-
v-model="fast"
27+
:id="key"
28+
v-model="typeOption[key]"
5729
type="checkbox"
5830
class="toggle"
59-
@change="handleChange('fast')"
31+
@change="handleChange(key)"
6032
>
61-
<label for="fast" class="label">
33+
<label :for="key" class="label">
6234
<div class="ball" />
6335
</label>
64-
<span>Fast</span>
36+
<span>{{ key.charAt(0).toUpperCase() + key.slice(1) }}</span>
6537
</div>
6638
</div>
6739
</template>

src/views/Day32_GoodCheapFast/index.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
flex-direction: column;
77
align-items: center;
88
justify-content: center;
9-
height: 100vh;
10-
width: 100vw;
11-
overflow: hidden;
12-
margin: 0;
139

1410
.toggle-container {
1511
display: flex;

src/views/Day33_NotesApp/Index.vue

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
const notesList = ref([])
33
44
onMounted(() => {
5-
notesList.value = JSON.parse(localStorage.getItem('noteslist'))
6-
? JSON.parse(localStorage.getItem('noteslist'))
7-
: []
5+
const cache = JSON.parse(localStorage.getItem('noteslist'))
6+
notesList.value = cache || []
87
})
98
109
function addNote() {
11-
const obj = reactive({
10+
const note = {
1211
text: '',
1312
showMain: true,
1413
showTextArea: true,
15-
})
14+
}
1615
17-
notesList.value.push(obj)
16+
notesList.value.push(note)
1817
}
1918
2019
function editNote(idx) {
@@ -27,25 +26,23 @@ function removeNote(idx) {
2726
2827
watch(
2928
notesList,
30-
(val) => {
31-
localStorage.setItem('noteslist', JSON.stringify(val))
32-
},
29+
val => localStorage.setItem('noteslist', JSON.stringify(val)),
3330
{ deep: true },
3431
)
3532
</script>
3633

3734
<template>
38-
<div class="body">
35+
<div class="body base_container">
3936
<button id="add" class="add" @click="addNote">
4037
<i class="fas fa-plus" /> Add note
4138
</button>
4239

43-
<div v-for="(note, index) in notesList" :key="index" class="note">
40+
<div v-for="(note, idx) in notesList" :key="idx" class="note">
4441
<div class="tools">
45-
<button class="edit" @click="editNote(index)">
42+
<button class="edit" @click="editNote(idx)">
4643
<i class="fas fa-edit" />
4744
</button>
48-
<button class="delete" @click="removeNote(index)">
45+
<button class="delete" @click="removeNote(idx)">
4946
<i class="fas fa-trash-alt" />
5047
</button>
5148
</div>

src/views/Day33_NotesApp/index.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
background-color: #7bdaf3;
55
font-family: 'Poppins', sans-serif;
66
display: flex;
7+
height: fit-content;
8+
min-height: calc(100vh - 100px);
79
flex-wrap: wrap;
8-
margin: 0;
9-
min-height: 100vh;
10-
width: 100vw;
1110
padding-top: 3rem;
1211

1312
.add {

src/views/Day34_AnimatedCountdown/Index.vue

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
<script setup>
2-
import { onMounted, ref } from 'vue'
3-
42
const count = ref(3)
53
let timer
64
const infinity = ref('infinite')
7-
onMounted(() => {
8-
runAnimation()
9-
})
5+
onMounted(() => runAnimation())
106
117
function replay() {
128
count.value = 3
@@ -25,19 +21,20 @@ function runAnimation() {
2521
}
2622
}, 1000)
2723
}
24+
25+
onUnmounted(() => clearInterval(timer))
2826
</script>
2927

3028
<template>
31-
<div class="body">
29+
<div class="body base_container">
3230
<div class="counter" :class="[infinity ? '' : 'hide']">
3331
<div class="nums">
34-
<span class="in_out" :style="{ '--infinite': infinity }">{{
35-
count
36-
}}</span>
32+
<span class="in_out" :style="{ '--infinite': infinity }">
33+
{{ count }}
34+
</span>
3735
</div>
3836
<h4>Get Ready</h4>
3937
</div>
40-
4138
<div class="final" :class="[infinity ? '' : 'show']">
4239
<h1>GO</h1>
4340
<button class="replay" @click="replay">

src/views/Day34_AnimatedCountdown/index.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@
22

33
.body {
44
font-family: 'Roboto', sans-serif;
5-
margin: 0;
6-
height: 100vh;
7-
width: 100vw;
85
background-color: skyblue;
9-
overflow: hidden;
106
position: relative;
117

128
.counter {

src/views/Day35_ImageCarousel/Index.vue

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<script setup>
2-
import { computed, onMounted, reactive, ref } from 'vue'
3-
4-
const imgList = reactive([
2+
const imgList = [
53
{
64
url: 'src/assets/imgs/001.jpg',
75
alt: 'first-image',
@@ -18,15 +16,14 @@ const imgList = reactive([
1816
url: 'src/assets/imgs/004.jpg',
1917
alt: 'fourth-image',
2018
},
21-
])
19+
]
2220
2321
const idx = ref(0)
2422
const translateX = ref(0)
2523
const imgWidth = ref(850)
26-
let interval
27-
onMounted(() => {
28-
interval = setInterval(run, 2000)
29-
})
24+
let timer
25+
onMounted(() => timer = setInterval(run, 2000))
26+
onUnmounted(() => clearInterval(timer))
3027
3128
const refTranslateX = computed(() => `${translateX.value}px`)
3229
const refImgWidth = computed(() => `${imgWidth.value}px`)
@@ -46,8 +43,8 @@ function run() {
4643
}
4744
4845
function resetInterval() {
49-
clearInterval(interval)
50-
interval = setInterval(run, 2000)
46+
clearInterval(timer)
47+
timer = setInterval(run, 2000)
5148
}
5249
5350
function prevImg() {
@@ -64,15 +61,15 @@ function nextImg() {
6461
</script>
6562

6663
<template>
67-
<div class="body">
64+
<div class="body base_container">
6865
<div class="carousel" :style="{ '--imgWidth': refImgWidth }">
6966
<div class="image-container" :style="{ '--translateX': refTranslateX }">
7067
<img
71-
v-for="(img, index) in imgList"
72-
:key="index"
68+
v-for="({ url: src, alt }) in imgList"
69+
:key="src"
7370
:style="{ '--imgWidth': refImgWidth }"
74-
:src="img.url"
75-
:alt="img.alt"
71+
:src
72+
:alt
7673
>
7774
</div>
7875

src/views/Day35_ImageCarousel/index.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
display: flex;
77
align-items: center;
88
justify-content: center;
9-
height: 100vh;
10-
width: 100vw;
11-
margin: 0;
129

1310
img {
1411
width: var(--imgWidth);

src/views/Day36_HoverBoard/Index.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script setup>
2-
import { ref } from 'vue'
3-
42
// 面板背景色
53
const bgColor = ref('#1d1d1d')
64
// 颜色列表
@@ -24,11 +22,11 @@ function getRandomColor() {
2422
</script>
2523

2624
<template>
27-
<div class="body">
25+
<div class="body base_container">
2826
<div id="container" class="container">
2927
<div
30-
v-for="i in 500"
31-
:key="i"
28+
v-for="key in 500"
29+
:key
3230
class="square"
3331
@mouseover="setColor"
3432
@mouseout="removeColor"

src/views/Day36_HoverBoard/index.scss

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
display: flex;
44
align-items: center;
55
justify-content: center;
6-
height: 100vh;
7-
width: 100vw;
8-
overflow: hidden;
9-
margin: 0;
106

117
.container {
128
display: flex;

0 commit comments

Comments
 (0)