refs are not automatically unwrapping in templates. #7386
Answered
by
liulinboyi
yogeshgalav
asked this question in
Help/Questions
-
I have exported ref property from Auth.js->User
now when I use this User property anywhere in template I need to define
instead of
why is this occuring. |
Beta Was this translation helpful? Give feedback.
Answered by
liulinboyi
Dec 22, 2022
Replies: 1 comment
-
Because the import value You can use like flow: user.js import { ref, reactive } from 'vue'
let User = ref(null);
let auth_user = localStorage.getItem("AuthUser");
if(auth_user) {
User.value = JSON.parse(auth_user);
}
/*
export default ref({
User,
})
*/
export default reactive({
User,
}) App.vue <script setup lang="ts">
import Auth from './user.js'
</script>
<template>
<div v-if="Auth.User">
{{ Auth.User }}
</div>
</template>
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
yogeshgalav
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Because the import value
Auth
is not reactive, when get the value, it will not trigger theget
method and notunref
in theget
method.You can use like flow:
playground
user.js
App.vue