mirror of
https://github.com/lainbo/component-party.git
synced 2026-04-05 13:09:03 +08:00
content: add context sample for vue3 (#151)
content: checking context for vue3 content: Changes for content Vue
This commit is contained in:
@@ -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
|
||||
|
||||
21
content/4-component-composition/5-context/vue3/App.vue
Normal file
21
content/4-component-composition/5-context/vue3/App.vue
Normal file
@@ -0,0 +1,21 @@
|
||||
<script setup>
|
||||
import { ref, provide } from "vue";
|
||||
import UserProfile from "./UserProfile.vue";
|
||||
|
||||
const user = ref({
|
||||
id: 1,
|
||||
username: "unicorn42",
|
||||
email: "unicorn42@example.com",
|
||||
});
|
||||
|
||||
function updateUsername(username) {
|
||||
user.value.username = username;
|
||||
}
|
||||
|
||||
provide("user", { user, updateUsername });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>Welcome back, {{ user.username }}</h1>
|
||||
<UserProfile />
|
||||
</template>
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user