當(dāng)前位置:首頁 > IT技術(shù) > Web編程 > 正文

使用mock.js偽造圖片數(shù)據(jù),圖片鏈接是枚舉值
2021-09-17 11:50:55

?

使用mock.js偽造圖片數(shù)據(jù),圖片鏈接是枚舉值_好友列表

?

const Mock = require('mockjs')
const moment = require('moment')

const getImage = () => {
  const urlArr = [
    'http://images.gongzuoshouji.cn/teacher/2021-08-09/84751fbcf153487f868a21a77048d19c.jpg',
    'http://images.gongzuoshouji.cn/teacher/20210804/196b0fa5d1726432492ad5edae6a565b.jpg',
    'http://images.gongzuoshouji.cn/teacher/20210730/a8e65bfaf7575a051a45b8dedd528af4.jpg',
  ]
  const index = Mock.Random.integer(0, urlArr.length - 1)
  return urlArr[index]
}

//初始化好友列表、群列表數(shù)據(jù)
const initFriendsList = () => {
  const friendsList = []
  const getList = ({type}) => {
    let arr = []
    for (let i = 0; i < 100; i++) {
      const temp = Mock.mock({
        name: '@cname',
        msg: '@ctitle',
        type,
        img: getImage() ,
        date: moment().subtract(i, 'day').format()
      })
      arr.push({ ...temp, id: i + 1 })
    }
    return arr
  }
  for (let i = 0; i < 4; i++) {
    friendsList.push({
      type: i + 1 + '',
      friends: getList({type: i + 1 + ''})
    })
  }
  return friendsList
}

const friendsList = initFriendsList()

使用mock.js偽造圖片數(shù)據(jù),圖片鏈接是枚舉值_表數(shù)據(jù)_02

?

?
?
?
?

本文摘自 :https://blog.51cto.com/x

開通會(huì)員,享受整站包年服務(wù)立即開通 >