new Vue({
el: '#app',
});
<body>
<div id="app"></div>
</body>
new Vue({
el: '#app',
data: {},
created() {},
computed: {},
methods: {},
...
});
Vue.component('name-of-component', {});
Vue.component('name-of-component', {
data() {
return {}
}
});
Vue.component('name-of-component', {
template: ``,
});
Vue.component('hello-world', {
template: '<div>Hello World</div>',
});
Vue.component('hello-world', {
template: `
<div>
<h1>Hello World</h1>
<p>This is the Hello World component</p>
</div>
`,
});
Vue.component('tweet-component', {
template: `
<div class="tweet" v-for="tweet in tweets" :key="tweet.id">
<div class="box">
<article class="media">
<div class="media-left">
<figure class="image is-64x64">
<img :src="tweet.img">
</figure>
</div>
<div class="media-content">
<div class="content">
<p>
<strong>{{tweet.name}}</strong>
<small>{{tweet.handle}}</small>
<br>
{{tweet.tweet}}
</p>
</div>
<div class="level-left">
<a class="level-item">
<span class="icon is-small">
<i class="fas fa-heart"></i>
</span>
<span class="likes">{{tweet.likes}}</span>
</a>
</div>
</div>
</article>
</div>
<div class="control has-icons-left has-icons-right">
<input class="input is-small" placeholder="Tweet your reply..." />
<span class="icon is-small is-left">
<i class="fas fa-envelope"></i>
</span>
</div>
</div>`
});
Vue.component('tweet-component', {
template: `
<div class="tweet" v-for="tweet in tweets" :key="tweet.id">
// ...
</div>
`,
});
tweets
props
<component greeting="Hello!"></component>
Vue.component('component', {
props: ['greeting'],
});
<tweet-component v-for="tweet in tweets"
:key="tweet.id"
:tweet="tweet">
</tweet-component>
Vue.component('tweet-component', {
props: ['tweet'],
});
Vue.component('tweet-component', { props: { tweet: { type: Object, required: true
}
},
});
Vue.component('tweet-component', {
// ...
});
Vue.component('name-of-component', {
template: ``,
});
const nameOfComponentObject = {
template: ``,
};
new Vue({
// ...,
components: {
'name-of-component': nameOfComponentObject
}
});
Component Object
Name of Component in template
<name-of-component></name-of-component/>
const tweetComponent = {
template: `...`,
props: ['tweet']
};
new Vue({
// ...,
components: {
'tweet-component': tweetComponent
}
});
props
props
props
const tweetContent = {
template: `..`,
props: ['tweet']
}
const tweetComponent = {
template: `...`,
props: ['tweet'],
components: {
'tweet-content': tweetContent
}
};
new Vue({
// ...,
components: {
'tweet-component': tweetComponent
}
});
Vue.component('name-of-component', {
// options
});
const nameOfComponentObject = {
// options
};
<template>
<div class="hello-world">
<h2>{{ getGreeting }}</h2>
<p>This is the Hello World component.</p>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
data () {
return {
reversedGreeting: '!dlrow olleH'
}
},
computed: {
getGreeting() {
return this.reversedGreeting.split("").reverse().join("");
}
}
}
</script>
<style scoped>
.hello-world {
width: 100%;
text-align: center;
}
</style>
npm install -g @vue/cli
vue create name_of_project
new Vue({
render: h => h(App)
}).$mount('#app');
.$mount('#app')
el: '#app'
new Vue({
render: h => h(App)
}).$mount('#app');
render (createElement) {
return createElement(App);
}
render (h) {
return h(App);
}
render: h => h(App)
Helpful Article (Sarah Drasner): what-does-the-h-stand-for-in-vues-render-method/
Helpful Comment (Bobby Juncosa): What is render: h => h (App)
new Vue({
el: '#app',
template: '<App />'
components: { App }
});
Global Components:
Component Variables:
Single File Components
Vue.component('name-of-component', {});
const nameOfComponentObject = {};
<template> section - HTML
<script> section - JS
<style> section - CSS
npm install -g @vue/cli
vue create name_of_project