Created
May 30, 2018 21:05
-
-
Save jameshulse/08a84f6ed2bd7156fc3b54af861ec402 to your computer and use it in GitHub Desktop.
Re-using component structure over multiple pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div> | |
<model-overview | |
:title="title" | |
:models="models" | |
@select="changeModel" | |
@add="createModel" | |
/> | |
<complex-form | |
v-if="selectedModel" | |
@update="updateModel" | |
:schema="formSchema" | |
/> | |
<slot v-else name="emptyState" /> | |
</div> | |
</template> | |
<script> | |
export default { | |
name: 'FormPage', | |
props: ['api'], | |
methods: { | |
createModel() { | |
this.api.create(); | |
}, | |
... | |
} | |
}; | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<form-page | |
title="Page One" | |
:api="api" | |
> | |
<template slot="empty-state"> | |
Empty state for page one | |
</template> | |
</form-page> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
api: { create() { axios.post('/model-one/') }, | |
}; | |
} | |
}; | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<form-page | |
title="Page Two" | |
:api="api" | |
> | |
<template slot="empty-state"> | |
Empty state for page two | |
</template> | |
</form-page> | |
</template> | |
<script> | |
export default { | |
data() { | |
return { | |
api: { create() { axios.post('/model-one/') }, | |
}; | |
} | |
}; | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment