Jakub Juszczak
Jakub Juszczak

Reputation: 7827

Why is my VueJs component not showing in the frontend?

I am trying to implement vuejs in a current django project. It kind of worked. However I wanted a cleaner structure and use vuejs components.

However the components are not showing up in the frontend.

So here I have my basic vue component (from the vueify-laravel example)

<template>
    <div>
        <h1>Hello, {{ name }}</h1>
        <input type="text" v-model="name">
    </div>
</template>

<script>
    export default {
        data: function() {
            return {
                name: 'Laracasts'
            };
        }
    };
</script>

<style>
    h1 {
        color: red;
    }
</style>

In my app.js I have

var Vue = require('vue')
import Greeter from './components/Greeter.vue'

new Vue({
    el: '#app',

    components: {
        greeter: Greeter
    }
});

And finally in one of my django templates

<div id="app">
    <greeter></greeter>
</div>

I have vue dev tools installed, and it shows me the root node and then the greeter node. But nothing in it. And the app container is empty too.

Upvotes: 2

Views: 4168

Answers (1)

Kurt
Kurt

Reputation: 2403

If the template is coming from django then you have to escape the {{ and }}. To turn off the template parsing use {% verbatim %} or you can also use {% templatetag openvariable %} (and then closevariable).

try:

{% verbatim %}
<template>
    <div>
        <h1>Hello, {{ name }}</h1>
        <input type="text" v-model="name">
    </div>
</template>
{% endverbatim %}

Upvotes: 11

Related Questions