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

Does this plug-in support vue3.x

Open tenPunchSuperman opened this issue 4 years ago • 7 comments

Does this plug-in support vue3.x ? And how to use on version vue3.x

tenPunchSuperman avatar Oct 25 '21 08:10 tenPunchSuperman

同问

study-bing avatar Oct 27 '21 01:10 study-bing

Same question.. Seems not..

acrolink avatar Jan 03 '22 20:01 acrolink

I have a similar plugin for vue3 and vue2 https://github.com/dreambo8563/next-vue-storage-watcher @tenPunchSuperman @study-bing @acrolink

dreambo8563 avatar Feb 15 '22 06:02 dreambo8563

在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

可以用的,不过导出的时候好像必须用ls这个名字, import Storage from 'vue-ls' const options = { namespace: 'testiiii__', // key prefix name: 'testls', // name variable Vue.[ls] or this.[$ls], storage: 'local', // storage name session, local, memory }

const { ls } = Storage.useStorage(options)

export default ls 具体可见https://www.npmjs.com/package/vue-ls

Big-Fruit avatar Mar 23 '23 10:03 Big-Fruit

也可以使用vue-lsp,这是另一个老哥基于这个写的,支持vue2.0和3.0

Big-Fruit avatar Mar 23 '23 10:03 Big-Fruit

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