C
C
chelkaz2017-06-18 22:52:32
Vue.js
chelkaz, 2017-06-18 22:52:32

Vue component. How to pass a template from import to template?

If so, then it works:

// Работает
Vue.component('my-component', {
    template: '<div>555</div>'
});

If so, then it doesn't work:
import Example from './components/Example.vue'

// test
Vue.component('my-component', {
    template: Example
});

Mistake:
[Vue warn]: invalid template option:[object Object]

The component itself:
<template>
    <div>
        I'm an example component!
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2017-06-19
@Fragster

import Example from './components/Example.vue'

// test
Vue.component('my-component', Example);

Well, you need to use nodejs and webpack. If there is no experience, then the easiest way to start is this: after installing nodejs in the console:
npm install vue-cli -g
vue-init webpack-simple testproject

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question