Skip to content

Instantly share code, notes, and snippets.

@Piglacquer
Last active January 30, 2019 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Piglacquer/167233b8a3c8a1ae82f7648aba028973 to your computer and use it in GitHub Desktop.
Save Piglacquer/167233b8a3c8a1ae82f7648aba028973 to your computer and use it in GitHub Desktop.
Basic layout of a Vue component with built out export default statement
<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