pinia参考这个:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<div id="app">
<p>
Counter: {{ store.counter }} Double: {{ store.double }}
</p>
<button @click="store.increment">Increment</button>
</div>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/vue3.2.22.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/VueDemi.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/pinia.js"></script>
<script>
const useStore = Pinia.defineStore({
id: 'main',
state: () => ({
counter: 0 }),
getters: {
double: state => state.counter * 2 },
actions: {
increment() {
this.counter++;
} } });
// 创建自定义插件
function createCustomPersistPlugin(options = {}) {
return ({ store }) => {
// 在插件初始化时从自定义存储引擎中加载状态
const persistedState = loadFromCustomStorage(options.key);
if (persistedState) {
// 将加载的状态应用到store
store.$patch(persistedState);
}
// 监听store的状态变化,将变化后的状态保存到自定义存储引擎
store.$subscribe((mutation, state) => {
saveToCustomStorage(options.key, state);
});
};
}
function loadFromCustomStorage(key) {
const persistedState = localStorage.getItem(key);
return persistedState ? JSON.parse(persistedState) : null;
}
function saveToCustomStorage(key, state) {
localStorage.setItem(key, JSON.stringify(state));
}
// 加载Pina插件
const customPersistPlugin = createCustomPersistPlugin({
key: 'myCustomStorageKey', // 设置自定义存储引擎的键
});
const pinia = Pinia.createPinia();
pinia.use(customPersistPlugin); //
const App = {
setup() {
const store = useStore();
return { store };
} };
const app = Vue.createApp(App).use(pinia);
app.mount('#app');
</script>
</body>
</html> 网友回复
如何让ai帮我自动在小红书或抖音上自动根据需求截流与潜在客户聊天拉客?
如果用go编写一个在virtualbox中启动的简单操作系统?
go如何搭建一个零信任网络?
如何用python实现一个公网代理访问软件?
如何用go实现一个公网代理访问软件?
如何用python实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
如何用go实现一个内网穿透打洞程序,实现内网的80端口暴露到公网上可以访问?
何为Shadowsocks 代理?
python如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?
nodejs如何实现类似php的opendir目录相互隔离的fastcgi多租户虚拟空间?


