小唯快跑啊
我怀疑这会显着提高可读性;无论如何,这是单行解构:let { data: {id, name, main, sys:{ country }, weather: [weather] }} = await api.getCity(cityName, units) // database callconst mockData = { data: { id: '1', name: 'john', main: 'something', sys: { country: 'International', foo: 'bar' }, weather: ['city1-rainy', 'city2-sunny'] } }; let { data: {id, name, main, sys:{ country }, weather: [weather] }} = mockData;console.log('id', id)console.log('name', name)console.log('main', main)console.log('country', country)console.log('weather', weather)