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

I'd like to ask about the progress of vue3 support

Open ddmy opened this issue 3 years ago • 6 comments

I'd like to ask about the progress of vue3 support, thanks

ddmy avatar Feb 25 '21 03:02 ddmy

Indeed, when I try to use it in VUE-CLI4, It will throw out this error: Uncaught TypeError: Object.defineProperty called on non-object at Function.defineProperty () at Object.install (vue-ls.js?c16e:501) at Object.use (runtime-core.esm-bundler.js?5c40:2972) at eval (main.js?56d7:8) at Module../src/main.js (app.js:1253)

yili001 avatar Jun 04 '21 13:06 yili001

+1

sschuchlenz avatar Jun 30 '21 14:06 sschuchlenz

+1

skywolf627 avatar Jul 13 '21 03:07 skywolf627

no one supports this project?

loknum avatar Jul 07 '22 07:07 loknum

在utils/index文件上 import Storage from 'vue-ls'; export const store = Storage.useStorage({ namespace: 'vue-', name: 'ls', storage: 'local', }).ls; 然后在页面按需引入import {store} from '@/utils' 使用store的set和get就可以了

qingyanmaodai avatar Jan 10 '23 03:01 qingyanmaodai

To easily migrate multiple Vue 2 apps that are dependent on having $ls property, I used the following:

import { MemoryStorage, WebStorage } from 'vue-ls/src/storage'

// eslint-disable-next-line
const _global = typeof window !== 'undefined' ? window : global || {}

/**
 * @type {import('vue').Plugin}
 */
const VueStorage = {
  install(app, options = {}) {
    const _options = Object.assign({}, options, {
      storage: options.storage || 'local',
      name: options.name || 'ls',
    })

    if (
      _options.storage &&
      ['memory', 'local', 'session'].indexOf(_options.storage) === -1
    ) {
      throw new Error(`Vue-ls: Storage "${_options.storage}" is not supported`)
    }

    let store = null

    switch (_options.storage) {
      case 'local':
        store = 'localStorage' in _global ? _global.localStorage : null
        break

      case 'session':
        store = 'sessionStorage' in _global ? _global.sessionStorage : null
        break
      case 'memory':
        store = MemoryStorage
        break
    }

    if (!store) {
      store = MemoryStorage
      console.error(
        `Vue-ls: Storage "${_options.storage}" is not supported your system, use memory storage`,
      )
    }

    const ls = new WebStorage(store)

    ls.setOptions(
      Object.assign(
        ls.options,
        {
          namespace: '',
        },
        _options || {},
      ),
    )

    app.config.globalProperties[`$${_options.name}`] = ls
  },
}

export default VueStorage

This is based in https://github.com/RobinCK/vue-ls/blob/e5bc3388b9e4f6c860dae3b4ab2b89f33e939c60/src/index.js, but with the last part changed (app.config.globalProperties).

tfoxy avatar Dec 08 '23 18:12 tfoxy