Vue Plugin: vuejs-storage

發表於
分類於 專案
This article is LLM-translated by GPT-4o, so the translation may be inaccurate or complete. If you find any mistake, please let me know.

This is a plugin for Vue that binds localStorage/sessionStorage, and can also be used with Vuex.

GitHub: https://github.com/maple3142/vuejs-storage

Simple TodoList example: maple3142/TodoList

Installation

Install: npm install vuejs-storage For browsers, you can use the CDN: https://unpkg.com/vuejs-storage

Code

<script src="https://unpkg.com/vue/dist/vue.min.js"></script>
<script src="https://unpkg.com/vuejs-storage/dist/vuejs-storage.min.js"></script>
<div id="vjss">
	<input type="text" v-model="text">
</div>
Vue.use(vuejsStorage) //安裝插件
new Vue({
	el: '#vjss',
	data: {
		text: ''
	},
	storage: {
		//使用storage選項
		namespace: 'vuejs-storage-example',
		//指定要存哪些變數
		keys: ['text']
	}
})

For more detailed tutorials, you can visit https://github.com/maple3142/vuejs-storage