typescript+vue3使用vue-ls
npm i vue-ls
新建 storage.ts
import Storage from 'vue-ls';
const options = {
namespace: 'vuejs__', // key prefix
name: 'ls', // name variable Vue.[ls] or this.[$ls],
storage: 'local', // storage name session, local, memory
};
const { ls } = Storage.useStorage(options)
export default ls
组件导入
<script lang="ts" setup>
import ls from "@/util/storage/"
ls.set('user','admin',60*60*1000)
</script>