vue-ls icon indicating copy to clipboard operation
vue-ls copied to clipboard

how to get all keys in storage?

Open anrananran opened this issue 3 years ago β€’ 2 comments

Vue.ls.set('token', 1)
Vue.ls.set('username', 'alice')
Vue.ls.keys() // expect output: ['token', 'username']

anrananran avatar Sep 29 '21 06:09 anrananran

This is how I did it, hope this helps! ❀️

import Vue from 'vue';
import Storage from 'vue-ls';

Vue.use(Storage, {
    namespace: 'app__',
    name: 'settings',
    storage: 'local',
});

Vue.settings.all = () => {
    const namespace = Vue.settings.options.namespace;

    const data = {};

    Object.keys(Vue.settings.storage).forEach((key) => {
        const prop = key.replace(namespace, '');
        
        data[prop] = Vue.settings.get(prop);
    });

    return data;
};

Then call:

// Vue component.

export default {
    created() {
        console.log(this.$settings.all());
    }
}

stevebauman avatar Nov 16 '21 00:11 stevebauman

it works, thank you! and maybe you can make a PR πŸ™„

anrananran avatar Nov 16 '21 02:11 anrananran