-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
content: add context sample for vue3 (#151)
content: checking context for vue3 content: Changes for content Vue
- Loading branch information
1 parent
c93483b
commit 6dd15a3
Showing
3 changed files
with
37 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<script setup> | ||
import { ref, provide } from "vue"; | ||
import UserProfile from "./UserProfile.vue"; | ||
const user = ref({ | ||
id: 1, | ||
username: "unicorn42", | ||
email: "[email protected]", | ||
}); | ||
function updateUsername(username) { | ||
user.value.username = username; | ||
} | ||
provide("user", { user, updateUsername }); | ||
</script> | ||
|
||
<template> | ||
<h1>Welcome back, {{ user.username }}</h1> | ||
<UserProfile /> | ||
</template> |
15 changes: 15 additions & 0 deletions
15
content/4-component-composition/5-context/vue3/UserProfile.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<script setup> | ||
import { inject } from "vue"; | ||
const { user, updateUsername } = inject("user"); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<h2>My Profile</h2> | ||
<p>Username: {{ user.username }}</p> | ||
<p>Email: {{ user.email }}</p> | ||
<button @click="() => updateUsername('Jane')"> | ||
Update username to Jane | ||
</button> | ||
</div> | ||
</template> |