diff --git a/src/views/sys/banner/index.vue b/src/views/sys/banner/index.vue index 21cbdf2..0a8d7be 100644 --- a/src/views/sys/banner/index.vue +++ b/src/views/sys/banner/index.vue @@ -310,7 +310,7 @@ export default { textOptTitle: "", listLoading: true, - selectedCountry: {}, + selectedCountry: {}, // 存储完整的国家对象 countryList: [], loadingCountry: false }; @@ -381,10 +381,21 @@ export default { const that = this; console.log("val", val); - that.selectedCountry = this.countryList.filter( - item => item.country.alphaTwo === val - )[0]; - that.listQuery.countryCode = this.selectedCountry.country.alphaTwo; + if (!val) { + // 如果没有选择国家,清空相关字段 + that.listQuery.countryCode = ""; + that.selectedCountry = {}; + } else { + // 选择了一个国家 + that.selectedCountry = + this.countryList.find(item => item.country.alphaTwo === val) || {}; + + // 使用传统的方式访问嵌套属性 + that.listQuery.countryCode = that.selectedCountry.country + ? that.selectedCountry.country.alphaTwo + : ""; + } + this.renderData(); }, @@ -397,7 +408,8 @@ export default { .then(res => { that.loadingCountry = false; that.countryList = res.body || []; - that.listQuery.countryCode = that.selectedCountry.country.alphaTwo; + that.listQuery.countryCode = ""; + that.selectedCountry = {}; // that.renderData(); }) .catch(er => {