
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
vue-cache-decorator
Advanced tools
a typescript decorator that can be used to cache the state of your vue component properties. the decorator works alongside with vue-class-component and vue2
This can be useful for example to cache a filter property so that when the user leaves the component and comes back the filter is still applied.
// table.vue
<template>
.....
</template>
<script lang="ts">
import Cache from 'vue-cache-decorator'
import Component from "vue-class-component";
import Vue from "vue";
@Component({})
export default class Table extends Vue {
@Cache()
filter = {
categoryId: 0,
page: 0,
limit: 10,
sort: 'createdAt',
}
}
</script>
whenever the user changes the filter, the new value is cached. the next time the user comes back to the component, the old filter value is retrieved from the localStorage.
npm install vue-cache-decorator
yarn add vue-cache-decorator
the decorator will create a watcher on the property and when the value changes, the new value is cached in the storage.
the decorator will also set the old value of the property when the component is created.
the last example is equivalent to the following:
// table.vue
import Cache from 'vue-cache-decorator'
import Component from "vue-class-component";
import Vue from "vue";
@Component({})
export default class Table extends Vue {
filter = {}
created() {
this.filter = JSON.parse(localStorage.getItem('Table-[filter]'))
this.$watch('filter', {
handler: (newValue) => {
localStorage.setItem('Table-[filter]', JSON.stringify(newValue))
},
deep: true,
})
}
}
the decorator function can accept an options object. the following options are available:
| Option | Description | Type | Default |
|---|---|---|---|
cacheKey | the storage key for the property when storing/retrieving | string | generated value ${componentName}-[${propertyName}] |
deep | vue deep watch | boolean | true |
cacheStore | the storage interface to use | Storage | window.localStorage |
except | property name(s) to ignore | string|string[] | undefined |
only | property name(s) only to be cached, mutually exclusive with except | string|string[] | undefined |
globalDispatch | fire a global window event on value change. newValue will be stored in event.detail property (on CustomEvent type). event name will be value of this property | string | undefined |
the decorator accept one type parameter. this can be used for auto-completion and auto-refactoring for property names in only and except options.
FAQs
caching the data of your vue component made easy
We found that vue-cache-decorator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.