Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
541 views
in Technique[技术] by (71.8m points)

vuejs3 - Empty Vue 3 reactive object on some pages

I have an object that I want to access from all my web app pages. I am using Vue 3 reactivity but I have noted that in some instances, I have to refresh the page to get the object.

How do I refactor my code to have the object always? See my code below:

import { reactive, watch } from "vue";
import getSchoolDocuments from "../composables/getSchoolDocuments";
import { projectAuth } from "../firebase/config";

let user = projectAuth.currentUser;

let userId;

if (!user) {
  userId = localStorage.getItem("userId");
} else {
  userId = user.uid;
}

const { error: schoolError, documents: schoolDetails } = getSchoolDocuments(
  "schools",
  userId
);

watch(schoolDetails, (newValue, oldValue) => {
  console.log(oldValue);

  school.id = newValue["id"];
  school.name = newValue["name"];
  school.staff = newValue["staff"];
  school.vehicles = newValue["vehicles"];
  school.contacts = newValue["contacts"];
 
});

export const school = reactive({
  id: "",
  name: "",
  staff: "",
  vehicles: "",
  error: schoolError
});
question from:https://stackoverflow.com/questions/65950533/empty-vue-3-reactive-object-on-some-pages

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...