[Vuejs]-How to maintain vue data changing url

0👍

You can create one array in store with your values like

urls: [{home: 1}, {details: 2}]

and when url changes just fetch values from store related to your current url

0👍

You can use somethings like s

<script>
export default {
  ...
  data() {
    return{
      currentPage: 1
    }
  },
  created() {
    const currentPage = localStorage.getItem('currentPage')
    if (currentPage > 0) {
      this.currentPage = currentPage
    }
  },
  methods: {
    setCurrentPage(value) {
      this.currentPage = value
      localStorage.setItem('currentPage', value)
    }
  },
  ...
}
</script>

Leave a comment