Skip to content

refs are not automatically unwrapping in templates. #7386

Discussion options

You must be logged in to vote

Because the import value Auth is not reactive, when get the value, it will not trigger the get method and not unref in the get method.

You can use like flow:

playground

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>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by yogeshgalav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants