Answer the question
In order to leave comments, you need to log in
How to register multiple components in Vue-JS?
I did not find an example in the documentation of how the registration of two components will look like.
something like this?
// register it with the tag <example>
Vue.component('loginmenu', loginMenu)
Vue.component('pagefooter', pageFooter)
new Vue({
el: '#loginmenu', '#pageFooter'
})
el: '#loginmenu', '#pageFooter'
window.onload = function() {
var loginMenu = Vue.extend({
template: `
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">
<img alt="Brand" src="">
</a>
</div>
</div>
</nav>
`
})
var pageFooter = Vue.extend({
template: `
<div class="panel panel-default">
<div class="panel-body">
Panel content
</div>
<div class="panel-footer">Panel footer</div>
</div>
`
})
// register it with the tag <example>
Vue.component('loginmenu', loginMenu),
Vue.component('pagefooter', pageFooter)
new Vue({
el: '#loginmenu' // как сюда новый компонент добавить?
})
}
Answer the question
In order to leave comments, you need to log in
The Vue object specifies a binding to some element of the page inside which all other components will already be mounted, for example
var App = Vue.extend({
template: `
<loginmenu></loginmenu>
<pagefooter></pagefooter>
`
})
new Vue({
el: 'body',
components: {
app: App
}
});
<body>
<app></app>
</body>
In main file:
import Vue from 'vue'
import App from './App.vue'
import Other from './Other.vue'
new Vue({
el: '#app',
template: '<App/><Other/>',
components: {
App: App,
Other: Other
}
})
<template>
<div id="app">
Hello
</div>
</template>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question