-
-
Save polodev/94935d99c2742422340ef86d52598736 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { defineStore } from "pinia"; | |
export let useCounterStore = defineStore('counter', { | |
// data | |
state() { | |
return { | |
count: 5 | |
}; | |
}, | |
// methods | |
actions: { | |
increment() { | |
if (this.count < 10) { | |
this.count++; | |
} | |
} | |
}, | |
// computed | |
getters: { | |
remaining() { | |
return 10 - this.count; | |
} | |
} | |
}); |
This file contains hidden or 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
<script setup> | |
import {useCounterStore} from "@/stores/CounterStore"; | |
let counter = useCounterStore(); | |
</script> | |
<template> | |
<div> | |
<h1>{{ counter.count }}</h1> | |
<button | |
@click="counter.increment()" | |
:disabled="! counter.remaining" | |
>Increment ({{ counter.remaining }} Remaining)</button> | |
</div> | |
</template> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment