代码优化
This commit is contained in:
@@ -85,7 +85,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import addressJson from '@/static/json/xinjiang.json';
|
||||
// 改为动态加载,避免主包过大
|
||||
let addressJson = null;
|
||||
export default {
|
||||
name: 'AreaCascadePicker',
|
||||
data() {
|
||||
@@ -154,12 +155,23 @@ export default {
|
||||
// this.areaData = resp.data.data;
|
||||
// }
|
||||
|
||||
// 暂时使用模拟数据
|
||||
// 动态加载JSON文件(使用require,支持动态加载)
|
||||
if (!addressJson) {
|
||||
try {
|
||||
// 优先从主包加载(如果存在)
|
||||
addressJson = require('@/static/json/xinjiang.json');
|
||||
} catch (e) {
|
||||
console.warn('无法加载地址数据,使用空数据', e);
|
||||
addressJson = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 使用模拟数据
|
||||
this.areaData = this.getMockData();
|
||||
} catch (error) {
|
||||
console.error('加载地区数据失败:', error);
|
||||
// 如果后端API不存在,使用模拟数据
|
||||
this.areaData = this.getMockData();
|
||||
// 如果加载失败,使用空数据
|
||||
this.areaData = addressJson || [];
|
||||
}
|
||||
},
|
||||
|
||||
@@ -338,7 +350,7 @@ export default {
|
||||
|
||||
// 模拟数据(用于演示)
|
||||
getMockData() {
|
||||
return addressJson
|
||||
return addressJson || []
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user