Skip to content

Commit 14b57ca

Browse files
committed
**Add 'Say Hello' feature with Vue component setup**
Introduced a new "Say Hello" feature, including an HTML entry point, Vue components, and reactive state management. Updated `vite.config.js` to include the new `say-hello.html` entry. This feature demonstrates name input, reactivity, and a counter functionality.
1 parent 49a8fb4 commit 14b57ca

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

say-hello.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite + Vue</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/say-hello.js"></script>
12+
</body>
13+
</html>

src/components/SayHello.vue

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<script setup>
2+
import {computed, reactive, ref} from "vue";
3+
4+
const person = reactive({
5+
firstName: "",
6+
lastName: ""
7+
})
8+
9+
function sayHello(){
10+
person.firstName = document.getElementById("firstName").value;
11+
person.lastName = document.getElementById("lastName").value;
12+
}
13+
14+
const fullName = computed((oldName) => {
15+
console.log(`change old name ${oldName}`);
16+
return `${person.firstName} ${person.lastName}`;
17+
})
18+
19+
const counter = ref(0);
20+
21+
function increment(){
22+
console.log(`increment called`);
23+
counter.value++;
24+
}
25+
</script>
26+
27+
<template>
28+
<div>
29+
<button v-on:click="increment">Increment {{counter}}</button> <br>
30+
<input placeholder="First Name" type="text" id="firstName"> <br>
31+
<input placeholder="Last Name" type="text" id="lastName"> <br>
32+
<button v-on:click="sayHello">Say Hello</button>
33+
</div>
34+
<h1>Hello {{ fullName }}</h1>
35+
</template>
36+
37+
<style scoped>
38+
39+
</style>

src/say-hello.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import {createApp} from "vue";
2+
import SayHello from "./components/SayHello.vue";
3+
4+
createApp(SayHello).mount("#app");

vite.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default defineConfig({
1010
index: "index.html",
1111
hello: "hello.html",
1212
counter: "counter.html",
13+
say_hello: "say-hello.html",
1314
}
1415
}
1516
}

0 commit comments

Comments
 (0)