Created
March 26, 2018 23:58
-
-
Save ahmedmusawir/b08baeaf4d7e1723a357928ff28467e3 to your computer and use it in GitHub Desktop.
VUE JS - SAMPLE COMPONENT - POSTS.VUE - GLOBAL AND LOCAL DECLARATIONS
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> | |
<ul> | |
<li v-for="item in ninjas">{{ item }}</li> | |
</ul> | |
</template> | |
<script> | |
export default { | |
data () { | |
return { | |
title: 'Ninja App', | |
ninjas: ['aaa', 'bbb', 'ccc'] | |
} | |
}, | |
methods: { | |
greeting: function() { | |
return 'This is a test method'; | |
} | |
} | |
} | |
</script> | |
<style lang="scss"> | |
ul { | |
border: 4px dotted red; | |
} | |
</style> | |
####################### | |
GLOBAL declaration | |
####################### | |
MAIN.JS | |
import Vue from 'vue' | |
import App from './App.vue' | |
import Posts from './components/Posts.vue' | |
Vue.component('posts', Posts) | |
new Vue({ | |
el: '#customer-spa', | |
render: h => h(App) | |
}) | |
#################### | |
LOCAL declaration | |
#################### | |
APP.VUE | |
<template> | |
<div id="customer-spa"> | |
<h1>{{ title }}</h1> | |
<h2>{{ greeting() }}</h2> | |
<posts></posts> | |
</div> | |
</template> | |
<script> | |
import Posts from './components/Posts.vue' | |
export default { | |
components: { | |
'posts': Posts | |
}, | |
data () { | |
return { | |
title: 'Your first Vue file, wooo!' | |
} | |
}, | |
methods: { | |
greeting: function() { | |
return 'This is a test method'; | |
} | |
} | |
} | |
</script> | |
<style lang="scss"> | |
#customer-spa { | |
border: 1rem solid white; | |
min-height: 500px; | |
} | |
</style> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment