Last active
January 30, 2019 16:00
-
-
Save Piglacquer/167233b8a3c8a1ae82f7648aba028973 to your computer and use it in GitHub Desktop.
Basic layout of a Vue component with built out export default statement
This file contains 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> | |
// Your html elements go in here | |
<Component v-bind:data='dataFromFetch' /> | |
// Using registered component and giving it data to do stuff with ^ | |
<template> | |
<script> | |
import Component from './components/Component' | |
import './styles/ComponentCSS' | |
export default { | |
name: 'ComponentName', | |
components: { | |
//Register imported components here, COMPONENTS ONLY | |
Component | |
}, | |
data(){ | |
return { | |
//Any data you want to save/use/pass to other components goes in here | |
dataFromFetch: [] | |
} | |
}, | |
props: ['dataFromParentComponent'], | |
// ^ Register data coming from parent | |
methods: { | |
// Where you write your functions | |
getData(){ | |
fetch('URL') | |
.then(resp => resp.json()) | |
.then(resp => this.dataFromFetch = resp) | |
} | |
}, | |
mounted(){ | |
//lifecycle method where you can automatically run functions | |
} | |
} | |
<script> | |
<style> | |
//write your css here, unless you imported it from an external file | |
</style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment