安装
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
网友评论