B
B
BonBon Slick2019-10-29 15:32:33
Vue.js
BonBon Slick, 2019-10-29 15:32:33

Disable router view cache?

The problem is this.
There is a Post and a list of recommendations in the sidebar.
We click on the sidebar, everything is OK, the post data has been changed, the cache works as it should.
We go to another page and then back to any page of the post, we get data from the cache that Vue updates, the result is clean data.
How to make vue router either update every time the post page or not update at all.
Now there is a watch listener for data substitution when switching to another post, however, when switching to a post from another page, say from a landing page, it processes the data request for the first time because it was like entering the page for the first time, and then it processes the listener that listens to the change in the post data . Since the last post is in Vuex, we updated it by going to the page, and then again through watch. This overwrites all the data that was from the previous post. For example, the user decided to hide the comments, of course, when going to any other post, regardless of which page, the comments should be hidden, but it turns out that they are not.

past_page.vue
<tempplate>
<post :details="postDetails"></post>
...
mounted(){
  this.postDetails = loadPost(id);
....

The code from post_page.vue works for the first time and only the first time when we enter the page, all further updates through the listener in post.vue.
post.vue
    watch:    {
            currentPostDetails(oldUrl, newUrl) {
                if (oldUrl === newUrl) {
                    return;
                }
             loadPost(id);
            },
        },

However, as described earlier, this approach forces vue to be called loadPost(id);twice if the user navigated to the page home_page.vue, for example, and then back to post.vuewhich overwrites the saved data in vuex.
<!--            <keep-alive>-->
            <!--                <router-view :key="$route.path"></router-view>-->
            <router-view></router-view>
            <!--            </keep-alive>-->

Keep-aliveor :key="$route.paththey all break.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question