-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added persistent Pinia state demo
- Loading branch information
Showing
4 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { defineStore } from 'pinia' | ||
|
||
const useCounterStore = defineStore('counter', () => { | ||
const counter = ref(0) | ||
|
||
const increment = () => { | ||
counter.value++ | ||
} | ||
|
||
return { | ||
counter, | ||
increment, | ||
} | ||
}, { | ||
persist: true, | ||
}) | ||
|
||
export default useCounterStore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<script setup lang="ts"> | ||
import { storeToRefs } from 'pinia' | ||
import useCounterStore from '@/stores/modules/counter' | ||
definePage({ | ||
name: 'counter', | ||
meta: { | ||
level: 2, | ||
}, | ||
}) | ||
const counterStore = useCounterStore() | ||
const { counter } = storeToRefs(counterStore) | ||
function add() { | ||
counterStore.increment() | ||
} | ||
// back | ||
const onClickLeft = () => history.back() | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<VanNavBar title="🍍 持久化 Pinia 状态" left-arrow fixed @click-left="onClickLeft" /> | ||
|
||
<div class="h-100vh w-full px-20 py-60"> | ||
<h1 class="text-6xl color-pink font-semibold"> | ||
Hello, Pinia! | ||
</h1> | ||
<p class="mt-4 text-gray-700 dark:text-white"> | ||
This is a simple example of persisting Pinia state. | ||
To verify its effectiveness, you can refresh the interface and observe it. | ||
</p> | ||
<p class="mt-4"> | ||
number:<strong class="text-green-500"> {{ counter }} </strong> | ||
</p> | ||
<button class="btn border-none btn-green" @click="add"> | ||
Add | ||
</button> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters