添加随机码代码实现
安装必要依赖 npm i - S uuid
import UUID from 'uuid' // UUID() '2c5ea4c0-4067-11e9-8bad-9b1deb4d3b7d' // 设置数据唯一标识 export const setRowKey = (data) => { return Object.assign({ rowKey: UUID() }, data) } // 数组遍历设置唯一标识 export const injectRowKey = (dataSource) => { return Array.isArray(dataSource) ? dataSource.map(setRowKey) : [] } const courseListFormat = injectRowKey(数组) courseListFormat: (5) [{…}, {…}, {…}, {…}, {…}] 0: {rowKey: "31c1bcc9-648b-4284-a553-b3872b8ee2bf", productId: 1621029, title: "8堂课教你买对保险", coverUrl: "https://course-static.xiaobangguihua.com/upload/59ed4224-7133-4608-9a4e-fe1ece45595a.png", simpleDesc: "用投资为生活锦上添花,用保险减少后顾之忧。", …} 1: {rowKey: "d31131e6-50ec-4214-9405-b44137b4ae36", productId: 1907389, title: "小帮共读-第一期", coverUrl: "https://course-static.xiaobangguihua.com/upload/3b8e705d-c737-4837-9d5e-900f5a766a3a.png", simpleDesc: "一起学习投资的经典书籍", …} 2: {rowKey: "2a696ecf-878a-4b7a-a55a-ca036aa50b2f", productId: 1030600, title: "小帮共读第二期", coverUrl: "https://course-static.xiaobangguihua.com/upload/9f52796b-8735-4322-8f35-6611c7bfed15.png", simpleDesc: "商品的一句话简介", …} 3: {rowKey: "f039a2eb-3411-462c-8d86-4b621629fbdb", productId: 1403144, title: "普通课程", coverUrl: "https://course-static.xiaobangguihua.com/upload/a886c572-c989-4e03-a97f-2b330e1f7ed0.jpg", simpleDesc: "普通课程一句话简介", …} 4: {rowKey: "a297c85b-037f-4f26-b8e9-4372e9f44e47", productId: 1841238, title: "新增商品商品名称改", coverUrl: "https://course-static.xiaobangguihua.com/upload/33495418-3054-4331-9c01-d02477a9dc59.png", simpleDesc: "新增商品一句话简介改", …} length: 5