mirror of
https://github.com/kevin-DL/build-gmail-clone-with-vue-3.git
synced 2026-01-24 07:55:34 +00:00
Mirage factories + models + seeds + faker
This commit is contained in:
@@ -1,29 +1,26 @@
|
|||||||
import { Server } from "miragejs"
|
import { Server, Model, Factory } from "miragejs"
|
||||||
|
import faker from 'faker';
|
||||||
|
|
||||||
new Server({
|
new Server({
|
||||||
|
models: {
|
||||||
|
email: Model
|
||||||
|
},
|
||||||
|
factories: {
|
||||||
|
email: Factory.extend({
|
||||||
|
subject(i) {
|
||||||
|
return `Email ${i}`
|
||||||
|
},
|
||||||
|
body(){
|
||||||
|
return faker.lorem.sentence()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
seeds(server){
|
||||||
|
server.createList('email', 10);
|
||||||
|
},
|
||||||
routes() {
|
routes() {
|
||||||
this.namespace = 'api';
|
this.namespace = 'api';
|
||||||
|
|
||||||
this.get('/emails', async () => {
|
this.get('/emails', {timing: 2000});
|
||||||
return [{
|
|
||||||
id: 1,
|
|
||||||
subject: 'First Steps',
|
|
||||||
body: 'Learning Vue with Vue 3, cool!',
|
|
||||||
read: false,
|
|
||||||
archived: false,
|
|
||||||
}, {
|
|
||||||
id: 2,
|
|
||||||
subject: 'Vue 3 - pretty cool',
|
|
||||||
body: 'Lots of really good features happening here',
|
|
||||||
read: false,
|
|
||||||
archived: false
|
|
||||||
}, {
|
|
||||||
id: 3,
|
|
||||||
subject: 'Do we have a released date?',
|
|
||||||
body: "I hear Q2 2020.",
|
|
||||||
read: true,
|
|
||||||
archived: false
|
|
||||||
}]
|
|
||||||
}, {timing: 2000})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
"@vue/cli-plugin-babel": "^4.2.0",
|
"@vue/cli-plugin-babel": "^4.2.0",
|
||||||
"@vue/cli-service": "^4.2.0",
|
"@vue/cli-service": "^4.2.0",
|
||||||
"@vue/compiler-sfc": "^3.0.0-alpha.9",
|
"@vue/compiler-sfc": "^3.0.0-alpha.9",
|
||||||
|
"faker": "^4.1.0",
|
||||||
"miragejs": "^0.1.35",
|
"miragejs": "^0.1.35",
|
||||||
"vue-cli-plugin-vue-next": "^0.0.4",
|
"vue-cli-plugin-vue-next": "^0.0.4",
|
||||||
"vue-template-compiler": "^2.6.11"
|
"vue-template-compiler": "^2.6.11"
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
export default {
|
export default {
|
||||||
async setup(props, {attrs, slots}){
|
async setup(props, {attrs, slots}){
|
||||||
let response = await fetch('/api/emails');
|
let response = await fetch('/api/emails');
|
||||||
let emails = await response.json();
|
let {emails} = await response.json();
|
||||||
|
|
||||||
return {emails}
|
return {emails}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3235,6 +3235,11 @@ fake-xml-http-request@^2.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/fake-xml-http-request/-/fake-xml-http-request-2.1.1.tgz#279fdac235840d7a4dff77d98ec44bce9fc690a6"
|
resolved "https://registry.yarnpkg.com/fake-xml-http-request/-/fake-xml-http-request-2.1.1.tgz#279fdac235840d7a4dff77d98ec44bce9fc690a6"
|
||||||
integrity sha512-Kn2WYYS6cDBS5jq/voOfSGCA0TafOYAUPbEp8mUVpD/DVV5bQIDjlq+MLLvNUokkbTpjBVlLDaM5PnX+PwZMlw==
|
integrity sha512-Kn2WYYS6cDBS5jq/voOfSGCA0TafOYAUPbEp8mUVpD/DVV5bQIDjlq+MLLvNUokkbTpjBVlLDaM5PnX+PwZMlw==
|
||||||
|
|
||||||
|
faker@^4.1.0:
|
||||||
|
version "4.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/faker/-/faker-4.1.0.tgz#1e45bbbecc6774b3c195fad2835109c6d748cc3f"
|
||||||
|
integrity sha1-HkW7vsxndLPBlfrSg1EJxtdIzD8=
|
||||||
|
|
||||||
fast-deep-equal@^3.1.1:
|
fast-deep-equal@^3.1.1:
|
||||||
version "3.1.1"
|
version "3.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
|
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz#545145077c501491e33b15ec408c294376e94ae4"
|
||||||
|
|||||||
Reference in New Issue
Block a user