跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Vue.js] vue2 缓存删除新思路

发表于

有这样的需求,页面组件开启 keepAlive 之后,通过关闭标签页关闭页面成功后,再进入开启缓存的页面发现那个页面依旧是缓存的状态,这就存在问题了,看了网上别的解决方案也没发现更好的,所以就想投机取巧一下。 既然 keepAlive 组件有一个 exclude 以及 include 状态,所以可以通过动态添加组件的 exclude 来控制。

 ```template
 <keep-alive :exclude="cachedComponents">
          <router-view v-if="$route.meta.keepAlive" class="avue-view"/>
        </keep-alive>
        
```

```js
   removeComponentFromCache(componentName) {
  this.cachedComponents.push(componentName);
  this.cachedComponents = this._.uniq(this.cachedComponents)
},
addComponentFromCache(componentName) {
  const index = this.cachedComponents.indexOf(componentName);
  if (index !== -1) {
    this.cachedComponents.splice(index, 1);
  }
},
```
然后通过动态的去调用这俩方法就可以达到关闭标签页的同时把组件缓存清空,当进入页面的时候再添加到 include 中,再继续缓存组件,亲测好用。大家有啥好办法也可以分享一下啊

Featured Replies

No posts to show

创建帐户或登录来提出意见

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.