Giter Site home page Giter Site logo

设置一个详情页keepAlive缓存,打开多个详情页。关闭其中一个,其它的详情页面会刷新 about v3-admin-vite HOT 5 CLOSED

un-pany avatar un-pany commented on August 16, 2024
设置一个详情页keepAlive缓存,打开多个详情页。关闭其中一个,其它的详情页面会刷新

from v3-admin-vite.

Comments (5)

pany-ang avatar pany-ang commented on August 16, 2024

这种情况先自己采用其他方式缓存吧,比如 localStorage

from v3-admin-vite.

pany-ang avatar pany-ang commented on August 16, 2024

现在系统采用的 Tag + keepAlive 的方式不好实现你所需要的需求

from v3-admin-vite.

pany-ang avatar pany-ang commented on August 16, 2024

你可以尝试将 addCachedView 代码更改为类似这样的逻辑,应该能满足你的需求:

  const addCachedView = (view: TagView) => {
    let totalByVisitedViews = 0
    let totalByCachedViews = 0
    for (let i = 0; i < visitedViews.value.length; i++) {
      if (visitedViews.value[i].name === view.name) totalByVisitedViews++
    }
    for (let i = 0; i < cachedViews.value.length; i++) {
      if (cachedViews.value[i] === view.name) totalByCachedViews++
    }
    if (typeof view.name !== "string") return
    if ((cachedViews.value.includes(view.name) && totalByVisitedViews < 2) ||totalByVisitedViews !== totalByCachedViews + 1) return
    if (view.meta?.keepAlive) cachedViews.value.push(view.name)
  }

但是这样的话,会导致你关闭其中一个详情页后再重新打开该详情页时,依旧是上一次缓存的数据,并且 Tag 右键刷新也会失效

from v3-admin-vite.

pany-ang avatar pany-ang commented on August 16, 2024

#98

from v3-admin-vite.

pany-ang avatar pany-ang commented on August 16, 2024

方案已给出,根据你的实际情况选择其中一种即可

from v3-admin-vite.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.