hez*_*ezf 4 vue.js vuejs3 pinia
在Vue3编译API\xef\xbc\x8c中我通常不使用this
但 pinia 的例子是:
\nincrement() {\n this.counter++\n},\nRun Code Online (Sandbox Code Playgroud)\n不想this在行动中使用。有什么建议吗?
您可以使用函数(类似于组件 setup())来定义 Store。然后你可以声明 actions 和 getter 而无需调用它。官方文档链接
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
function increment() {
count.value++
}
return { count, increment }
})
Run Code Online (Sandbox Code Playgroud)