mock.js

作者: _花 | 来源:发表于2018-02-24 17:49 被阅读0次

安装

npm install mockjs

mock.js

import Mock from 'mockjs';

export default Mock.mock('http://g.cn', {

         "data|4": [
            {
                'name'    : '@name',
                'age|1-100': 100,
                'color'    : '@color',
                'address|1' :[
                     "北京市",
                     "天津市",
                     "河北省",
                     "山西省"
                ]
            }
          ]


});

hello.vue

<template>
  <div class="hello">
  <h2 v-for="item in msg">
  <p>姓名:{{item.name}} 年龄: {{item.age}} 喜欢颜色:{{item.name}} 住址:{{item.address}}</p>
  </h2>
  </div>
</template>

<script>
import data from '../assets/mock';
import axios from "axios"
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg:[],
    }
  },
  mounted(){
    axios.get('http://g.cn').then(res => {
      this.msg = res.data.data;
      console.log(res)
    })
  }
}
</script>

image.png

相关文章

网友评论

      本文标题:mock.js

      本文链接:https://www.haomeiwen.com/subject/qwhcxftx.html