Es6里面的解析结构
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<h1>数组以序列号一一对应,这是一个有序的对应关系</h1>
<h1>而对象根据属性名一一对应,这是一个无序的对应关系</h1>
<script type="text/javascript">
// 首先有这么一个对象
const props = {
userName: 'button',
loading: false,
clicks: true,
disabled: 'disabled'
}
//当我们想要取得其中的2个值:loading与clicked时:
// es5
var loading = props.loading;
var click = props.clicks;
console.log(loading)
console.log(clicks)
//es6
const { loading, clicks } = props;
// 给一个默认值,当props对象中找不到loading时,loading就等于该默认值
const { loading = false, clicks } = props;
例子
// 比如
// section1
import React, { Component } from 'react';
// section2
export { default } from './Button';
// section3
const { click, loading } = this.props;
const { isCheck } = this.state;
</script>
</body>
</html>