前端开发时如果后端的接口还没写好,可以先将测试数据写在js文件中,引入文件的数据检验web逻辑是否正确
测试数据
创建一个js文件
const testData = {
MatchFieldList: {
MatchField: [
{
ID: 1,
UserDefine: "11",
PlatformDefine: 0
},
{
ID: 2,
UserDefine: "22",
PlatformDefine: 1
}
],
TotalNum: 2,
PageIndex: 0,
PageSize: 0
}
};
export default testData;
vue文件中使用
引入
import testData from './testData.js';
使用
打印 testData.MatchFieldList; 就可以拿到数据了
返回为promise类型
有些场景需要将测试数据包装为promise返回
return new Promise(resolve => {
console.log("testData.testData", testData.MatchFieldList);
resolve(testData.MatchFieldList);
});