mock数据模拟和使用

安装mock,和案axios

npm i mockjs

npm i axios 

后再vue组件中使用

<script>
import axios from 'axios'
import Mock from 'mockjs'
const Random = Mock.Random;

Mock.mock('http://123.com', {
// 'name|3': 'fei', //这个定义数据的模板形式下面会介绍
'shuju|10':[{
'ip':'@ip',
'dizhi':'@province',

"number|1-100.1-10": 1,
'age|20-30': 1,
'id|+1': 1,
"city|56":[{"city":'@city(true)'}],
"star|1-10": "★",
"goodName": "@cname()",
"goodsPrice|100-1000": 100,
"goodsurl":"@image('200x100', '#894FC4', '#FFF', 'png', '')",
"object|2": {
"310000": "上海市",
"320000": "江苏省",
"330000": "浙江省",
"340000": "安徽省"
}
}]
})
export default {
data(){
return {
cunru:[]
}
},

created() {},
methods: {
dianji() {
axios.get("http://123.com").then(res => {
console.log(res.data.shuju);
this.cunru=res.data.shuju
})
}
}
}
</script>

 

或者

写入mockbase.js :

 

 

 

 

 

使用:

 

posted @ 2019-07-07 15:02  开江鱼gty  阅读(444)  评论(0编辑  收藏  举报