示例仅供参考,请以真机为主

Store 缓存

使用 Piniaopen in new window,轻量级状态管理库;

统一在 /store 目录下新建:

示例

import { defineStore } from "pinia";
import { ref } from "vue";

const useTestStore = defineStore("test", function () {
	const count = ref<number>(0);

	function add() {
		count.value += 1;
	}

	return {
		count,
		add
	};
});

export default useTestStore;

使用

import useTestStore from "/@/store/test";

const test = useTestStore();

test.add();

console.log(test.count);
Last Updated: