ITPub博客

首页 > IT职业 > > axios如何将mock数据改为用api数据的url获取真实数据呢?

axios如何将mock数据改为用api数据的url获取真实数据呢?

作者:ilovelily 时间:2019-04-17 15:59:55 0 删除 编辑

user.js

const Users = [
{
 

for (let i = 0; i < 86; i++) {
  Users.push(Mock.mock({
    id: Mock.Random.guid(),
    name: Mock.Random.cname(),
    addr: Mock.mock('@county(true)'),
    'age|18-60': 1,
    birth: Mock.Random.date(),
    sex: Mock.Random.integer(0, 1)
  }));
}

]}

export { LoginUsers, Users, Informations };



user.vue

export default {
  data() {
   return {
    filters: {
      _id: ''
    },
        loading: false,
    informations: []
   }
  },
  created() {
            axios.get('informations')
                 .then(response => {
                     this.informations = response.data
                 })
                 .catch(e => {
                     this.errors.push(e)
                 })
        }


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1441/viewspace-3154435/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-15

  • 博文量
    116
  • 访问量
    702