programing

Vue.js에서 가져온 소스에서 개체의 실제 값 가져오기

luckcodes 2022. 8. 7. 18:26

Vue.js에서 가져온 소스에서 개체의 실제 값 가져오기

【API】【API】의로부터 데이터를 나라 .VueX그런 다음 돌연변이를 사용하여 국가 목록을 주에 저장합니다.

저는 this.$state.getters.countryList포넌넌컴이제 해당 목록에 변수가 있는지 비교해야 합니다.

저는 이런 : ㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴㄴ.this.$store.getters.countryList.indexOf('usa').

은 있다'usa'하지만, 「 」 「 」 「 」 「 。-1결과적으로.

이 .this.$state.getters.countryList를 사용하여console.log(this.$state.getters.countryList) 나는 ★★★★★★★★★★★★★★★★★★★★★★★★★★★★.[__ob__: Observer]결과적으로 콘솔에 표시됩니다.

이게 내가 하려는 일이야.

  mounted() {
    if (this.$store.getters.countryList.indexOf('usa')) {
       //Do something
      }
  }

실제 수 요?this.$state.getters.countryList.indexOf()아, 른른른 른기?

이기 때문에async@Phil에서 언급한 것처럼 필요한 시점에 액세스하려는 데이터를 사용할 수 없을 수 있습니다.

에, 를 설정하고, 할 수 .fetch되어 「」가 됩니다.countryList로딩되어 있습니다.

»store.js 예를 , 이 '', '아까', '아까', '아까', '아까', '아까', '아까', '아까', 이렇게 나왔다고 칩시다countryListnull「CHANGE MARGE:」

export const state = () => ({
 countryList: null
})

그 your your your thenmounted()「CHANGE MARGE:」

mounted() {
 this.$store.watch(
  state => state.countryList,
  (value) => {
   if (value) { 
     //instruction once countryList is loaded 
   }
  }
 )
}

언급URL : https://stackoverflow.com/questions/62526895/getting-the-true-value-of-an-object-from-a-fetched-source-in-vue-js