Use easy mock replace mockjs

pull/38/merge
lin-xin 2017-05-24 14:46:32 +08:00
parent 1b37000c3e
commit 7d3d32de07
10 changed files with 129 additions and 56 deletions

View File

@ -34,6 +34,10 @@ module.exports = {
pathRewrite:{
'/api':''
}
},
'/ms':{
target: 'https://www.easy-mock.com/mock/592501a391470c0ac1fab128',
changeOrigin: true
}
},
// CSS Sourcemaps off by default because relative paths are "buggy"

View File

@ -13,7 +13,6 @@
"axios": "^0.15.3",
"babel-polyfill": "^6.23.0",
"element-ui": "1.3.1",
"mockjs": "^1.0.1-beta3",
"vue": "^2.3.2",
"vue-core-image-upload": "2.1.11",
"vue-datasource": "1.0.9",

View File

@ -13,12 +13,6 @@
<el-table-column prop="name" label="姓名" width="120">
</el-table-column>
<el-table-column prop="address" label="地址" :formatter="formatter">
</el-table-column>
<el-table-column label="头像">
<template scope="scope">
<img :src="scope.row.logo">
</template>
</el-table-column>
<el-table-column label="操作" width="180">
<template scope="scope">
@ -43,6 +37,7 @@
export default {
data() {
return {
url: '../../../static/vuetable.json',
tableData: [],
cur_page: 1
}
@ -57,8 +52,11 @@
},
getData(){
let self = this;
this.$axios.post('/api/table',{page:self.cur_page}).then((res) => {
self.tableData = res.data.data;
if(process.env.NODE_ENV === 'development'){
self.url = '/ms/table/list';
};
self.$axios.post(self.url, {page:self.cur_page}).then((res) => {
self.tableData = res.data.list;
})
},
formatter(row, column) {

View File

@ -24,6 +24,7 @@
data: function(){
const self = this;
return {
url: '../../../static/datasource.json',
information: {
pagination:{},
data:[]
@ -81,7 +82,10 @@
}
},
beforeMount(){
axios.get('/api/source').then( (res) => {
if(process.env.NODE_ENV === 'development'){
this.url = '/ms/table/source';
};
axios.get(this.url).then( (res) => {
this.information = res.data;
})
}

View File

@ -6,7 +6,6 @@ import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-default/index.css'; // 默认主题
import '../static/css/theme-green/index.css'; // 浅绿色主题
import "babel-polyfill";
import './mock/index.js';
Vue.use(ElementUI);
Vue.prototype.$axios = axios;

View File

@ -1,21 +0,0 @@
export const datasource = [
{
path: '/api/source',
data: {
'data|10':[{
'id|+1':1,
'name':'@cname',
'email':'@email',
'ip':'@ip'
}],
"pagination": {
"total": 15,
"per_page": 15,
"current_page": 1,
"last_page": 1,
"from": 1,
"to": 15
}
}
}
]

View File

@ -1,11 +0,0 @@
import Mock from 'mockjs';
import {vuetable} from './vuetable.js';
import {datasource} from './datasource.js';
let data = [].concat(vuetable,datasource);
data.forEach(function(res){
Mock.mock(res.path, res.data);
});
export default Mock;

View File

@ -1,13 +0,0 @@
export const vuetable = [
{
path: '/api/table',
data: {
'data|10':[{
'date':'@date',
'name':'@cname',
'address':'@county(ture)',
'logo':'@image("24x24",@color,@cfirst)'
}]
}
}
]

71
static/datasource.json Normal file
View File

@ -0,0 +1,71 @@
{
"data": [{
"id": 1,
"name": "段娜",
"email": "g.rgiuory@kctbut.mw",
"ip": "68.28.4.232"
},
{
"id": 2,
"name": "蔡洋",
"email": "y.mwjjoje@lpkshev.tg",
"ip": "22.126.12.189"
},
{
"id": 3,
"name": "陈敏",
"email": "e.voaiiuo@mvng.sn",
"ip": "227.89.13.37"
},
{
"id": 4,
"name": "朱平",
"email": "e.lduuf@nkfypn.az",
"ip": "9.39.240.243"
},
{
"id": 5,
"name": "侯平",
"email": "t.czqjyndts@jmwenklns.md",
"ip": "178.162.29.113"
},
{
"id": 6,
"name": "常超",
"email": "d.dhysgem@uxpcutmlk.tt",
"ip": "192.50.103.170"
},
{
"id": 7,
"name": "许平",
"email": "g.fiqdonvbc@wanepptw.tv",
"ip": "73.20.99.60"
},
{
"id": 8,
"name": "毛超",
"email": "w.unyyejh@qus.gt",
"ip": "10.88.135.123"
},
{
"id": 9,
"name": "周磊",
"email": "e.qbejguqqg@ejpxhltoak.gw",
"ip": "244.221.237.210"
},
{
"id": 10,
"name": "胡秀英",
"email": "s.dszo@uxaojtj.sy",
"ip": "86.199.17.210"
}
],
"pagination": {
"total": 15,
"per_page": 15,
"current_page": 1,
"last_page": 1,
"from": 1,
"to": 15
}
}

43
static/vuetable.json Normal file
View File

@ -0,0 +1,43 @@
{
"list": [{
"date": "1997-11-11",
"name": "林丽",
"address": "吉林省 辽源市 龙山区"
}, {
"date": "1987-09-24",
"name": "文敏",
"address": "江西省 萍乡市 芦溪县"
}, {
"date": "1996-08-08",
"name": "杨秀兰",
"address": "黑龙江省 黑河市 五大连池市"
}, {
"date": "1978-06-18",
"name": "魏强",
"address": "广东省 韶关市 始兴县"
}, {
"date": "1977-07-09",
"name": "石秀兰",
"address": "江苏省 宿迁市 宿豫区"
}, {
"date": "1994-09-20",
"name": "朱洋",
"address": "海外 海外 -"
}, {
"date": "1980-01-22",
"name": "傅敏",
"address": "海外 海外 -"
}, {
"date": "1985-10-10",
"name": "毛明",
"address": "内蒙古自治区 包头市 九原区"
}, {
"date": "1975-09-08",
"name": "何静",
"address": "西藏自治区 阿里地区 普兰县"
}, {
"date": "1970-06-07",
"name": "郭秀英",
"address": "四川省 巴中市 恩阳区"
}]
}