store.state里面调用的数据要怎么才可以在当前程序直接调用呢

store.state里面调用的数据要怎么才可以在当前程序直接调用呢

const courseChaptersFindAll = computed(() => store.state.templates.courseChaptersFindAll)
    const searchParamss =  computed(() => ({ page: 1, rows: 800, pId: 0, webSiteId: csWebSiteId,sortType: 1,columnType: 2,status: 1 }))
    onMounted(() => {
        store.dispatch('userCourseChaptersFindAll',  { searchParams: searchParamss.value })
    })

我通过上面这个代码获取到数据之后,要怎么才可以直接使用呢

https://img1.sycdn.imooc.com/climg/65a50c1e096bacd815470635.jpg

像这样直接点他的属性出来,要怎么处理呢

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
张轩 2024-01-16 09:56:35

同学你好

抱歉没有看懂你的意思, 你说的直接调用是什么意思?在哪里调用呢?

而且你这个 computed 返回的应该是在 value 属性中用,至少应该是  

courseChaptersFindAll.value.xxx


  • 提问者 妖刀雪饮 #1

    老师,大概就是我使用

    VUEX请求数据的话,是不能直接返回的必须要我把页面渲染完成之后,才可以拿到数据,不然就为null
    2024-01-17 12:12:40
  • 提问者 妖刀雪饮 #2
    const searchParamss =  computed(() => ({ page: 1, rows: 800, pId: 0, webSiteId: csWebSiteId,sortType: 1,columnType: 2,status: 1 }))
        onMounted(() => {
            store.dispatch('userCourseChaptersFindAll',  { searchParams: searchParamss.value })
        })

    我使用这个接口请求数据,并把数据保存到VUEX里面

     const courseChaptersFindAll = computed(() => store.state.templates.courseChaptersFindAll)

    然后通过这个方法读取数据,是不能立即读取到我服务器上返回的数据的必须要等页面渲染完成,我在次触发才可以读取到VUEX上保存的数据,请问要怎么样才可以立即从vuex哪来拿到我服务器端返回的数据呢

    2024-01-17 12:16:17
  • 张轩 回复 提问者 妖刀雪饮 #3

    同学你好


    对于 vue 和 react 这样的框架,假如选择是spa 这种方式,那么只能等页面渲染完再发送请求,如果你要必须完成这样的需求,可以选择 nuxt 这种 ssr 框架。

    2024-01-18 09:44:57
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师