我对 vuejs 3 和 vuex 4 还很陌生。我正在尝试做一些像 getter 这样简单的事情。由于它对我不起作用,我制作了一个 console.log 来查看结果是否出现在控制台中。结果是这样的:CompulatedRefImpl {dep:undefined,_dirty:true,__v_isRef:true,effect:ReactiveEffect,_setter:f,...}... 我认为我必须在计算中实现 ref ,用于从存储 getter 获取信息,但我不知道在这种情况下该怎么做。
state: {
title:'hello'
},
getters: {
title: state => state.title
},
<template>
{{title}}
</template>
<script>
import {computed, ref} from 'vue'
import {useStore} from 'vuex'
export default {
name: 'Lista',
setup(){
const store = useStore();
const nuevaSerie = ref("");
let title = ref("");
/* const borrar_todo = async (index) =>{
store.dispatch ('lista/borrar_todo',{
index
})
}
const nueva_serie = async (nombre) =>{
store.dispatch ('lista/nueva_serie',{
nombre
})
}
const colores = async (index) =>{
await new Promise( (aceptar)=>{
setTimeout( ()=>{
aceptar()
},100)
})
store.dispatch ('lista/colores', index)
}*/
title = computed(() => store.getters.title)
console.log(title)
let series = store.state.lista.series
return { series, nuevaSerie, nueva_serie, borrar_todo, colores, title}
}
}
</script>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
终于找到错误了。调用 store getter 的方式是错误的。我澄清“lista”是模块的名称