Skip to content

Commit 84ee765

Browse files
authored
Update README.md
1 parent 0bc54e5 commit 84ee765

File tree

1 file changed

+42
-119
lines changed

1 file changed

+42
-119
lines changed

README.md

+42-119
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
1-
#Vue Lifecycle Hooks Demo
2-
This is a simple Vue.js project that demonstrates the usage of Vue lifecycle hooks through a basic counter application. The project showcases how to use Vue 3, set up lifecycle hooks, and manage reactive state.
3-
4-
Table of Contents
5-
Project Setup
6-
Usage
7-
Understanding Vue Lifecycle Hooks
8-
Example Code
9-
Project Setup
1+
## Table of Contents
2+
3+
1. Project Setup
4+
2. Usage
5+
3. Understanding Vue Lifecycle Hooks
6+
4. Example Code
7+
8+
9+
## Project Setup
10+
1011
To get started with this project, you need to follow these steps:
1112

12-
Clone the repository:
13+
### 1. Clone the repository:
14+
git clone <your-repository-url>
15+
cd vue-simple-setup
16+
### 2. Open the index.html file in your browser:
17+
You don't need to set up a local server for this simple project. Just open the index.html file directly in your browser.
1318

14-
sh
15-
Copy code
16-
git clone <your-repository-url>
17-
cd vue-simple-setup
18-
Open the index.html file in your browser:
19-
You don't need to set up a local server for this simple project. Just open the index.html file directly in your browser.
19+
## Usage
2020

21-
Usage
2221
This project demonstrates a counter application with increment and decrement buttons. The application uses Vue.js to manage the state and handle button click events. The Vue lifecycle hooks are logged to the console at different stages of the component's lifecycle.
2322

24-
HTML Structure
23+
### HTML Structure
24+
2525
The HTML file sets up the basic structure of the application:
2626

27-
html
28-
Copy code
27+
```
28+
import copyCodeBlock from '@pickra/copy-code-block';
2929
<!DOCTYPE html>
3030
<html lang="en">
3131
<head>
@@ -47,11 +47,13 @@ Copy code
4747
<script src="script.js"></script>
4848
</body>
4949
</html>
50-
CSS Styling
50+
```
51+
52+
### CSS Styling
53+
5154
The CSS file provides basic styling for the application:
5255

53-
css
54-
Copy code
56+
```
5557
* {
5658
padding: 0;
5759
margin: 0;
@@ -97,11 +99,14 @@ Copy code
9799
border: none;
98100
transition: all 0.3s ease;
99101
}
100-
JavaScript Logic
102+
103+
```
104+
105+
### JavaScript Logic
106+
101107
The JavaScript file sets up the Vue application and demonstrates various lifecycle hooks:
102108

103-
js
104-
Copy code
109+
```
105110
const app = Vue.createApp({
106111
// Lifecycle Hooks
107112
@@ -172,103 +177,21 @@ const app = Vue.createApp({
172177
});
173178
174179
app.mount("#app");
175-
Understanding Vue Lifecycle Hooks
176-
Vue lifecycle hooks are methods that allow you to hook into different stages of a component's lifecycle. Here are the main lifecycle hooks used in this project:
177180
178-
beforeCreate: Called before the data object is created. At this point, the component is being initialized, but reactive data and methods are not yet available.
181+
```
179182

180-
created: Called after the data object is created. The component's data and methods are now available, making it a good place to fetch data or perform initial setup tasks.
181183

182-
beforeMount: Called before the component is mounted to the DOM. The component's template has been compiled, but it hasn't been inserted into the DOM yet.
183184

184-
mounted: Called after the component is mounted to the DOM. The component's DOM elements are now accessible, making it a good place to interact with the DOM or perform side effects.
185185

186-
beforeUpdate: Called before the component updates due to reactive data changes. This hook is useful for performing tasks before the DOM is updated.
186+
## Understanding Vue Lifecycle Hooks
187187

188-
updated: Called after the component updates due to reactive data changes. This hook is useful for interacting with the updated DOM or performing post-update logic.
189-
190-
beforeDestroy: Called before the component is destroyed. This hook is useful for performing cleanup tasks, such as removing event listeners or timers.
191-
192-
destroyed: Called after the component is destroyed. The component's DOM elements and data are no longer available.
193-
194-
Example Code
195-
Here's the complete code for the Vue Lifecycle Hooks Demo:
188+
Vue lifecycle hooks are methods that allow you to hook into different stages of a component's lifecycle. Here are the main lifecycle hooks used in this project:
196189

197-
index.html
198-
html
199-
Copy code
200-
<!DOCTYPE html>
201-
<html lang="en">
202-
<head>
203-
<meta charset="UTF-8" />
204-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
205-
<title>Vue Lifecycle Hooks Demo</title>
206-
<link rel="stylesheet" href="style.css" />
207-
</head>
208-
<body>
209-
<h1>Exploring Vue Lifecycle Hooks</h1>
210-
<div id="app">
211-
<div class="counter">
212-
<button @click="increment">+</button>
213-
<span>{{ count }}</span>
214-
<button @click="decrement">-</button>
215-
</div>
216-
</div>
217-
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
218-
<script src="script.js"></script>
219-
</body>
220-
</html>
221-
style.css
222-
css
223-
Copy code
224-
* {
225-
padding: 0;
226-
margin: 0;
227-
box-sizing: border-box;
228-
}
229-
230-
body {
231-
background-color: #343a40;
232-
color: white;
233-
font: 1em sans-serif;
234-
text-align: center;
235-
padding: 20px;
236-
}
237-
238-
.counter {
239-
display: flex;
240-
justify-content: center;
241-
align-items: center;
242-
gap: 30px;
243-
margin: 20px;
244-
padding: 20px;
245-
border-radius: 10px;
246-
background-color: #29323a;
247-
color: #f0f0f0;
248-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
249-
}
250-
251-
.counter button {
252-
background-color: transparent;
253-
border: none;
254-
outline: none;
255-
cursor: pointer;
256-
font-size: 1.5em;
257-
font-weight: bold;
258-
color: inherit;
259-
border-radius: 5px;
260-
transition: all 0.3s ease;
261-
}
262-
263-
.counter button:active {
264-
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
265-
outline: none;
266-
border: none;
267-
transition: all 0.3s ease;
268-
}
269-
script.js
270-
js
271-
Copy code
272-
const app = Vue.createApp({
273-
beforeCreate() {
274-
console.log("beforeCreate
190+
1. beforeCreate: Called before the data object is created. At this point, the component is being initialized, but reactive data and methods are not yet available.
191+
2. created: Called after the data object is created. The component's data and methods are now available, making it a good place to fetch data or perform initial setup tasks.
192+
3. beforeMount: Called before the component is mounted to the DOM. The component's template has been compiled, but it hasn't been inserted into the DOM yet.
193+
4. mounted: Called after the component is mounted to the DOM. The component's DOM elements are now accessible, making it a good place to interact with the DOM or perform side effects.
194+
5. beforeUpdate: Called before the component updates due to reactive data changes. This hook is useful for performing tasks before the DOM is updated.
195+
6. updated: Called after the component updates due to reactive data changes. This hook is useful for interacting with the updated DOM or performing post-update logic.
196+
7. beforeDestroy: Called before the component is destroyed. This hook is useful for performing cleanup tasks, such as removing event listeners or timers.
197+
8. destroyed: Called after the component is destroyed. The component's DOM elements and data are no longer available.

0 commit comments

Comments
 (0)