作者:mobiledu2502890917 | 来源:互联网 | 2023-10-12 19:06
这篇文章给大家分享的是有关vue模拟后台数据调试的示例分析的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
首先创建一个本地json文件,放在项目中如下
{
"runRedLight":{
"CurrentPage": 1,
"TotalPages": 0,
"TotalItems": 0,
"ItemsPerPage": 100,
"Items":[
{"DEVICEID":"121212","DEVICETYPE":"1","DEVICETIME":"2016-10-10","CREATEDTIME": "2016-10-11"},
{"DEVICEID":"124412","DEVICETYPE":"1","DEVICETIME":"2016-10-10","CREATEDTIME": "2016-10-11"},
{"DEVICEID":"121255","DEVICETYPE":"1","DEVICETIME":"2016-10-10","CREATEDTIME": "2016-10-11"},
{"DEVICEID":"121266","DEVICETYPE":"1","DEVICETIME":"2016-10-10","CREATEDTIME": "2016-10-11"}
]
},
"redLightRoad": [
{"CREATEDTIME":"2017-03-03 09:41:44","DEVICEID":"2","ID":"45afdc60f33443d28fe0171d0df40d14","NAME":"1"},
{"CREATEDTIME":"2017-03-03 09:41:52","DEVICEID":"5","ID":"74cf7106f1fa406f9c32ad351e7dfc76","NAME":"2"}
]
}
然后在dev-server.js中配置
1.数据读取
var appData = require('../data.json');
var runRedLight = appData.runRedLight;
var redLightRoad = appData.redLightRoad;
2.定义路由
var apiRoute = express.Router();
apiRoute.get('/runRedLight',function(req, res){
res.json({
errno:0,//错误码
data: runRedLight//具体数据
})
})
apiRoute.get('/redLightRoad',function(req, res){
res.json({
errno:0,
data: runRedLight
})
})
3.注册定义的api
app.use('/api',apiRoute);
4.在页面使用url
this.$http.get("/api/runRedLight").then((response) => {
response = response.body;
console.log(response.data);//需要这样获取到数组
});
感谢各位的阅读!关于“vue模拟后台数据调试的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!