我通過從外部 API 中獲取數據來獲取國家/地區列表VueX。然后我使用突變將這些國家列表存儲到一個州。所以實際上,我將國家存儲在一個變量中,我this.$state.getters.countryList從一個組件中引用它?,F在我需要比較該列表中是否存在變量。所以我用這個方法: this.$store.getters.countryList.indexOf('usa').'usa'我知道該列表中存在一個事實,但我總是得到-1結果。然后我嘗試this.$state.getters.countryList通過 using調試值,并在控制臺中console.log(this.$state.getters.countryList)得到[__ob__: Observer]結果。這就是我想要做的: mounted() { if (this.$store.getters.countryList.indexOf('usa')) { //Do something } }如何獲得實際值this.$state.getters.countryList并將其與執行檢查一起使用indexOf()以執行其他操作?
從 Vue.js 中獲取的源中獲取對象的真實值
拉丁的傳說
2022-10-13 19:32:51