Skip to content

Commit

Permalink
content: add context sample for vue3 (matschik#151)
Browse files Browse the repository at this point in the history
content: checking context for vue3

content: Changes for content Vue
  • Loading branch information
ismailassa authored Feb 10, 2023
1 parent c93483b commit 6dd15a3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ How do we solve this ? Developers love having framework overview by examples. It
- [x] Emit to parent
- [x] Slot
- [x] Slot fallback
- [ ] Context
- [x] Context
- [x] Form input
- [x] Input text
- [x] Checkbox
Expand Down
21 changes: 21 additions & 0 deletions content/4-component-composition/5-context/vue3/App.vue
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 content/4-component-composition/5-context/vue3/UserProfile.vue
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>

0 comments on commit 6dd15a3

Please sign in to comment.