Home > other >  Vue js my data lost after reloading my page
Vue js my data lost after reloading my page

Time:04-30

I have a page reload problem.
When I save on Vscode it works correctly on my html page, but when I refresh the page my data is undefined.
The data in the store works well, however it's just on the view profile that it doesn't work only after reloading my page.
If you have any suggestions, I'm a taker, I don't know what to do anymore.

views/Profil:

<div >
            <span  id="form-lastName">Nom :</span>
            <input
              type="text"
              
              aria-label="Username"
              v-model="lastName"
              ref="string"
            />
          </div>
          <div >
            <span  id="form-firstName">Prénom :</span>
            <input
              type="text"
              
              aria-label="Username"
              v-model="firstName"
              ref="string"
            />
          </div>


----------


export default {
  name: "ProfilC",
  data: function () {
    return {
      lastName: "",
      firstName: "",
      selectedFile: "",
    };
  },
  components: {
    NavbarC,
  },
  mounted: function () {
    this.lastName = this.$store.state.userInfos.user_lastName;
    this.firstName = this.$store.state.userInfos.user_firstName;


----------
sotre/index.js

const store = createStore({
  state: {
    status: '',
    user: user,
    userInfos: {
      nom: '',
      prenom: '',
      email: '',
      image: '',
    },
    dataArticles: [],
    dataComments: [],
    articleInfos: {
      message: '',
      image: '',
    },
    comments: [],
  },

  mutations: {
    
    userInfos: function (state, userInfos) {
      state.userInfos = userInfos;
    },
},

CodePudding user response:

I see your using vuex , did you install vuex persisted-state is saved the data on page reload

  • Related