programing

Vuex - 저장 상태 개체가 알 수 없는 유형입니다.

goodcopy 2022. 8. 2. 23:30
반응형

Vuex - 저장 상태 개체가 알 수 없는 유형입니다.

/src/middlewares/auth.ts 파일:

import store from '@/store'

export default {
  guest(): void {
    if (store.state.auth.authenticated === false) {
      // do some action
    }
  }
}

/src/store.ts 파일:

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    auth
  }
})

/src/store/auth.ts:

import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'

@Module
export default class Auth extends VuexModule {
  public authenticated: boolean = false
}

오류: ,, TS 러::::::: ts ts ts ts ts ts ts ts ts 。Object is of type 'unknown'

나의 ★★★★★★★★★★★★★★★★★.npm run build? 떻게게입?입 력??store이류류 라라? ???

업데이트 1

한다.if (store.state.auth.authenticated === false)

여기에 이미지 설명 입력

업데이트 2

다음의 3개의 파일의 디렉토리 구조:

  • /src/middlewares/auth.ts
  • /src/store.ts
  • /src/store/auth.ts

업데이트 3

store.state.auth.authenticated로로 합니다.store.state그러면 컴파일러가 불평을 멈춥니다. 내 스토어 auth.ts 파일과 관련된 것 같습니다. 어떻게든 정의를 입력해야 합니다.

보기: 로그로켓

export default function auth ({ next, store }){
 if(!store.getters.auth.loggedIn){
     return next({
        name: 'login'
     })
 }

 return next()
}

첫 번째 인수는 {store}을(를) 정의하는 개체입니다.

export default guest ({ store }, to: any ...){

언급URL : https://stackoverflow.com/questions/57467586/vuex-store-state-object-is-of-type-unknown

반응형