A Vue.js project
bash
# install dependencies
npm install
# serve with hot reload at localhost:8080
npm run dev
import Mock from 'mockjs'
Mock.mock('/user/list', 'post', {
// 属性 list 的值是一个数组,其中含有 1 到 10 个元素
'list|1-10': [{
// 属性 id 是一个自增数,起始值为 1,每次增 1
'id|+1': 1,
'name' : '@name',
'age|1-100': 100,
'color' : '@color'
}]
})
import axios from 'axios'
import Vue from 'vue'
require('@/services/mock.js')
Vue.prototype.$axios = axios
<template>
<div class="hello">
<p v-for="(item,index) in user.list">
id: <span>{{item.id}}</span>
color: <span>{{item.color}}</span>
name: <span>{{item.name}}</span>
age: <span>{{item.age}}</span>
</p>
</div>
</template>
<script type="text/babel">
export default {
data () {
return {
user: []
}
},
mounted () {
this.$axios({
url: '/user/list',
method: 'post',
data: {
userId: 12
}
}).then(res => {
this.user = res.data
}).catch(err => {
// console.log(err)
})
},
methods: {
}
}
</script>
<style lang="stylus" scoped>
</style>