vuex getter如何函数定义
Vuex getter可以通过函数来定义。在定义getter时,可以传递state参数,并返回一个计算属性。以下是一个示例:
// 定义getter
const getters = {
fullName: (state) => {
return `${state.firstName} ${state.lastName}`
}
}
// 使用getter
this.$store.getters.fullName
在上面的示例中,getter使用了state参数,将firstName和lastName拼接成fullName,并返回该属性。在使用getter时,可以通过this.$store.getters.fullName来获取计算属性的值。
原文地址: https://www.cveoy.top/t/topic/bgLa 著作权归作者所有。请勿转载和采集!