Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@johnnywang/vuex-localstorage
Advanced tools
A Vuex Plugin, help dealing with Vuex data & Web LocalStorage. Since LocalStorage could not automatically interact with some Vue APIs, such as computed
, Vuex getters
, or v-model
.
$ npm i @johnnywang/vuex-localstorage
or
$ yarn add @johnnywang/vuex-localstorage
/* main.js */
import Vue from 'vue'
import App from './App.vue'
// Vuex store instance
import store from './store'
// import LocalStore
import LocalStore from '@johnnywang/vuex-localstorage'
// register
LocalStore.register(store);
new Vue({
store,
render: h => h(App)
}).$mount('#app')
Remember to register LocalStore module before new Vue using your
store
instance.
By registering LocalStore, it will create a Vuex module named LocalStore
, it can be accessed by this.$store.LocalStore
which we dont recommend to do.
Initiate the LocalStore module by calling initLocalStorage
in Vuex, this only has to be called once in your App's entrypoint.
/* App.vue */
import { mapActions } from 'vuex'
export default {
name: 'App',
methods: {
...mapActions('LocalStore', ['initLocalStorage']),
},
created() {
this.initLocalStorage();
}
}
This method checks user's localStorage, then inject the data into your Vuex.
After registering, the LocalStore
module has been inject into whole Vue instance globally by name $ls
by default, which can also set as stateKey
in Options.
<!-- Hello.vue -->
<template>
<div>{{ $ls }}</div>
</template>
<script>
export default {
name: 'Hello'
}
</script>
In another Vuex module action, we can access it in rootState.LocalStore.$ls
.
Globally wherever you want, even in another Vuex module's action, you can use editLocalStore
method. It receives an object with key
& value
, which will change data in Vuex & refresh localStorage automatically.
/* Game.js */
// Another Vuex module
const actions = {
someHandler({ dispatch }) {
dispatch('editLocalStore', {
key: 'name',
value: 'Kevin Yan',
}, { root: true });
}
};
/* Hello.vue */
import { mapActions } from 'vuex';
export default {
name: 'Hello',
methods: {
...mapActions(['editLocalStore']),
},
mounted() {
this.editLocalStore({
key: 'name',
value: 'Gogo brother',
});
}
};
Use bindLocalStore
method, we can bind LocalStore data into components's computed
, then use in v-model
<!-- Hello.vue -->
<template>
<input type="checkbox" v-model="show" />
</template>
<script>
import { bindLocalStore } from '@johnnywang/vuex-localstorage';
export default {
name: 'Hello',
computed: {
show: bindLocalStore('show'),
}
};
</script>
This just help you bind the getter/setter
of computed with data
& editLocalStore
.
Be aware that, you don't need to import
editLocalStore
when usingbindLocalStore
, even though you still can do it with other uses.
state
{}
By default, state is empty. You can add some default value to localStore in state
.
import store from './store';
import LocalStore from '@johnnywang/vuex-localstorage';
// register
LocalStore.register(store, {
state: {
name: 'Johnny',
age: 100,
show: false
}
});
getters
{}
Getters to be set in Vuex module.
stateKey
$ls
The global access key to module state.
userKey
store
real key for Web LocalStorage where stores the data from Vuex.
encode
false
Encode data stores in Web LocalStorage.
set expire
key into state
as following:
LocalStore.register(store, {
state: {
name: 'Johnny',
age: 100,
show: false,
expire: '2020-03-01' // String will put into new Date()
}
});
if the user's localstorage data had contain expire
key, then if expire date is over now, the data will be injected into Vuex, if the data is outdated, it will be overwriten by Vuex's setting default.
This plugin is for small use case, and should not be used for storing any sensitive data, we do not responsed for the consequences.
Copyright (c) 2020-present, Johnny Wang
FAQs
A tiny plugin for Vuex, handling with localStorage
We found that @johnnywang/vuex-localstorage 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.