搜索

首页  >  问答  >  正文

当使用 getter 检索状态数据并将其显示在组件中时,我做错了什么?

我对 vuejs 3 和 vuex 4 还很陌生。我正在尝试做一些像 getter 这样简单的事情。由于它对我不起作用,我制作了一个 console.log 来查看结果是否出现在控制台中。结果是这样的:CompulatedRefImpl {dep:undefined,_dirty:true,__v_isRef:true,effect:ReactiveEffect,_setter:f,...}... 我认为我必须在计算中实现 ref ,用于从存储 getter 获取信息,但我不知道在这种情况下该怎么做。

1

2

3

4

5

6

7

8

9

10

state: {

   

  title:'hello'

},

 

getters: {

 

title: state => state.title

 

},

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

<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>

P粉517814372P粉517814372365 天前518

全部回复(1)我来回复

  • P粉797855790

    P粉7978557902024-03-30 00:19:02

    终于找到错误了。调用 store getter 的方式是错误的。我澄清“lista”是模块的名称

    1

    sssccc

    回复
    0
  • 取消回复