qq_40251771 2023-07-06 12:58 采纳率: 0%
浏览 151
已结题

vue vite pinia 跳转页面时会显示pinia中的action not a function

vue跳转页面时第一子路由页面偶尔会显示Pinia中的action not a function,而跳转的另一个同级路由页面一定会报错 对应的pinia action is not a function 都是刷新后就有了,求解答

页面js:

import { useEnterStore } from '@/store/main/userenter/userEnter'
import { storeToRefs } from 'pinia'

import { ref } from 'vue'
import { formatUTC } from '@/utils/format'

import { localCache } from '@/utils/cache'

const userId = localCache.getCache('userId')

//const userStore = useUserStore()
const userEnterStore = useEnterStore()

//const userId = userStore.userId
const currentPage = ref(1)
const webpageSize = ref(6)

//查询
function fetchEnterListData(queryInfo: any = {}) {
  //获取offset和size
  const pageSize = webpageSize.value
  const pageIndex = currentPage.value

  const info = { pageIndex, pageSize }
  //带参数查询时将数组组合在一起
  const totalquery = { ...info, ...queryInfo }

  userEnterStore.postUserEnterListAction(totalquery)
}
fetchEnterListData({ userId: userId.id })
const { enterList, enterTotalCount } = storeToRefs(userEnterStore)


```路由
import { useEnterStore } from '@/store/main/userenter/userEnter'
import { storeToRefs } from 'pinia'

import { ref } from 'vue'
import { formatUTC } from '@/utils/format'

import { localCache } from '@/utils/cache'

const userId = localCache.getCache('userId')

//const userStore = useUserStore()
const userEnterStore = useEnterStore()

//const userId = userStore.userId
const currentPage = ref(1)
const webpageSize = ref(6)

//查询
function fetchEnterListData(queryInfo: any = {}) {
  //获取offset和size
  const pageSize = webpageSize.value
  const pageIndex = currentPage.value

  const info = { pageIndex, pageSize }
  //带参数查询时将数组组合在一起
  const totalquery = { ...info, ...queryInfo }

  userEnterStore.postUserEnterListAction(totalquery)
}
fetchEnterListData({ userId: userId.id })
const { enterList, enterTotalCount } = storeToRefs(userEnterStore)
```javascript



```报错

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/549034916886196.png "#left")
  • 写回答

10条回答 默认 最新

  • qq_40251771 2023-07-06 13:12
    关注

    pinia store的内容

    
    import { userEnterListData } from '@/service/main/userEnter/userEnter'
    import { defineStore } from 'pinia'
    import { ElMessage } from 'element-plus'
    
    interface ISystenState {
      enterList: any[]
      enterTotalCount: number
      userId: number | string
    }
    export const useEnterStore = defineStore('system', {
      state: (): ISystenState => ({
        enterList: [],
        enterTotalCount: 0,
        userId: 0
      }),
      actions: {
        async postUserEnterListAction(queryInfo: any) {
          const userListResult = await userEnterListData(queryInfo)
          if (userListResult.code !== 200) {
            ElMessage.error(userListResult.message)
          } else {
            const totalCount = userListResult.data.total
            const enterlist = userListResult.data.records
            this.enterList = enterlist
            this.enterTotalCount = totalCount
          }
        }
      }
    })
    
    评论

报告相同问题?

问题事件

  • 系统已结题 7月14日
  • 创建了问题 7月6日

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号