解构赋值在项目中的应用
// 1 当数组作为参数的时候
// for 循环 数组内的数字相加
// sun += arr[i]
// const sum = arr => { // 箭头函数一个参数可以去掉括号 (arr)
// let result = 0
// for (let i = 0; i < arr.length; i++) {
// result += arr[i]
// }
// console.log(result)
// }
// sum([1, 2, 3])
// const sum = ([a, b, c]) => {
// console.log(a + b + c)
// }
// sum([1, 2, 3])
// 2 当对象作为参数的时候
// const foo = ({name, age, school="xx学校"}) => { // school为函数参数的默认值
// console.log(name, age, school)
// }
// foo({
// name: '张三',
// age: 20,
// school: 'hekeying'
// })
// 3 当函数作为参数的时候
// const foo = () => {
// return {
// name: '张三',
// age: 20,
// }
// }
// const {name, age} = foo()
// console.log(name, age)
// 4 参数的对换
// let a = 1;
// let b = 2;
// [b, a] = [a, b]
// console.log(a, b)
// 5 json js的对象表示法
// const json = '{"name": "es", "price": "500"}'
// // const obj = JSON.parse(json)
// // console.log(obj)
// const {name, price} = JSON.parse(json)
// console.log(name, price)
// 6 axios 请求应用
async created () {
// const res = await axios.get('http://jsonplaceholder.typicode.com/users')
// console.log(res)
// this.userList = res.data
// 解构赋值
const { data } = await axios.get('http://jsonplaceholder.typicode.com/users')
console.log(data)
this.userList = data // 取到想用的数组数据
}

浙公网安备 33010602011771号