what is pinia
like vuex pinia manage reactive state across your app
Pinia is built to help you manage reactive data and state across your components in your application.
why migrate from vuex to pinia
vuex code
import { createStore } from 'vuex'
const CounterStore = createStore({
state() {
return {
count: 0
}
},
actions: {
increment(context) {
context.commit('incrementCount')
}
},
mutations: {
incrementCount(state) {
state.count++
}
}
})
=
in pinia no mutation, directly call state froma ctions
// The following is pseudocode
import { createStore } from 'pinia'
const CounterStore = createStore({
state() {
return {
count: 0
}
},
actions: {
increment() {
state.count++
}
}
})
=
// Calling an action with Vuex store.$dispatch('increment') // Calling an action with Pinia store.increment()
typescripts supports pinia
because of typescript => auto suggestion
No comments:
Post a Comment