All Projects → sumnow → vue-mock-templates

sumnow / vue-mock-templates

Licence: MIT License
vue template init webpack

Programming Languages

javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects

vue-mock-templates

快速创建vue-mock-template 模版

npm i vue-mock-templates

mockvue c myproject

cd myproject & yarn

yarn dev

依赖

"chalk": "^2.1.0",
"commander": "^2.11.0",
"fs-extra": "^4.0.2"

集成localMock的vue-template

集成了 localMock 功能的 vue-cli

打开 localhost:8080 查看效果,点击文字发起Mock请求,主要关注请求为services目录下,

// index.js
// 请求的配置
const obj = {
    apiIn: id => {return {url: `/wechat/${id}`, method: 'post'}},
    apiIn2: {url: '/wechat/asd', method:'post'},
    apiIn3: {url: '/wechat/es', method:'post'},
    apiNot: {url: '/wechat/config', method:'post'},
}

export default filterAPIinTest(obj)

属性值可以为函数或者对象,同 $.ajax 的参数方式,包括 url , method 等,如果配置项为可变属性,则输入函数即可。

// testAPI.js
export {
    "apiIn": `$m.obj({name: cstr(2,3)})`
}

testAPI里配置每个接口的mock返回值,按照 locaMock 的语法,只有再testAPI里的接口才会被Mock,其他的接口都不会,可以渐进式地替换Mock数据。

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].