search

Home  >  Q&A  >  body text

angular.js - 关于angularjs变量被浏览器“缓存”的问题

请教。我在pc站里用angular,是个课程主页,点击收藏是用的angular,问题是:点击收藏后,再点进入课程跳转到别的页面,然后再点击浏览器的回退,退到课程主页后,发现收藏状态不是刚刚操作后的结果,好像是js里的变量缓存了。请问这个怎么解决呢?

曾经蜡笔没有小新曾经蜡笔没有小新2745 days ago609

reply all(4)I'll reply

  • 为情所困

    为情所困2017-05-15 17:03:29

    This problem should not occur. According to my idea, the collection status of your page should be controlled by a certain data passed to you by the backend. After you click Collection, send a request to the backend, and then the backend Update that data and return that data to you. As long as this data is updated, won't your collection status be updated? No matter how you enter the page, the collection status should be some data returned to you by the backend, and it will not follow the progress of your browser. There has been a change in going back. I don’t know if my explanation is the same as what you asked

    reply
    0
  • 仅有的幸福

    仅有的幸福2017-05-15 17:03:29

    Can you post the relevant code?

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-15 17:03:29

    First of all, your collection interacts with the server. Secondly, when your page jumps, the controller of the previous page has been destroyed, and there is no variable cache. I think it is necessary for you to retrieve the collected data when the controller is initialized and then display it on the page

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-15 17:03:29

    As long as the URL is changed, the current Controller will be destroyed. When you jump to the interface again by changing the URL, the data in the scope will be initialized data, unless the background sets a value for the object

    reply
    0
  • Cancelreply