Pinia Getters
# 箭头函数
不能使用this,this指向已经改变指向undefined,修改值请用state
主要作用类似于computed 数据修饰并且有缓存
getters:{
newPrice:(state)=>`${state.user.price}`
}
1
2
3
2
3
# 普通函数
使用this
//类似于computed 可以帮我们去修饰我们的值
getters: {
newName():string{
return `${this.name}`
}
}
# 互相调用
getters:{
newCurrent ():number | string {
return ++this.current + this.newName
},
newName ():string {
return `$-${this.name}`
}
},
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
上次更新: 2025/11/15, 15:21:19