-
-
Save damianof/63a18280a89df7de6c4491353a31f3bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import { reactive, ref, onMounted } from 'vue' | |
| export const useDeskree = (props) => { | |
| const userInfo = ref({}) | |
| //the user object that has some user functions such as login ... | |
| const user = { | |
| get() { | |
| return loggedInUser | |
| }, | |
| //other functions | |
| } | |
| //this function run on the mounted hook it fetches the user data. | |
| async function initUser(userId) { | |
| if (typeof props.userId === "string") { | |
| try { | |
| const res = await dbRestRequest(`/users/${userIdOrUser}`) | |
| userInfo.value = { | |
| ...res.data | |
| } | |
| } catch {} | |
| //ctach an other staff | |
| } | |
| } | |
| onMounted(async () => { | |
| await initUser() | |
| }) | |
| return { | |
| user: userInfo | |
| } | |
| } |
This file contains hidden or 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
| //I want to make the get function awaits for initUser so it doesn't return a null | |
| <script setup> | |
| const { user } = useDeskree(); | |
| console.log(user.value) // should now log | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment