实验室react项目名词解释

fetch:  获取,抓取 。一般用于获取后代数据。

promise 对象:一个object ,保存异步操作的结果。 

then 方法: promise.then((v)=>{}), 接受两个回调函数作为参数(第二个可选),其中promise对象作为then方法中函数的参数。

get 方法 和 post 方法 : 同样用于获取后台数据。

json 数据: 一种轻量级的文本数据交换格式,js对象表示法,json 是 js 的子集。

json 有两种数据结构: 1. 对象: {key:value,....}  2. 数组:[ {key:value}, {key:value}...{}..]。

json 字符串:符合json数据格式的js字符串   ,let jsonStr = "{name:'yangw',sex:'man',id:124}"。

json 对象:符合json数据格式的js对象 ,let jsonObj = {name:'yangw',sex:'man',id:123}。

用js使用json对象:

例如:定义一个json对象,var obj = {

        name: "yangw",

        year: 12,

        books: [   // 数组结构json对象,可嵌套使用。

          { id: 1, name: "《原则》" },

          { id: 2, name: "《心理学》" }

        ],

        object: {   //对象结构的json对象,同上。

          id: 3,

          disc: '对象里的对象,嵌套'

        }

}  

读取写son中的数据,可用 '.'操作符和['key']两种方式。

例如: obj.name , obj.book[0].id 或 obj.book[1].['id']  // 1 , obj.object.disc 或 obj.object.['disc'] 。

写和修改: obj.name = "json",  删除: delete obj.name, 遍历:for (var v in obj) { console.log(obj.[v]) }。

dispatch : 分发,用于发送action。

async 关键字:  异步的,  异步箭头函数:const func = async () => {} 。

async (异步)函数总是返回promise对象:

例如 :async(异步)函数的promise是resolved时:  async function asyncFunc() { return 123 } ;    asyncFunc().then( x => console.log(x) ) // 123。

            async(异步)函数的promise是rejected是:async function asyncFunc() { throw new Error("Problem") };  asyncFunc().then( err => console.log(err) ) // Problem。