1

I'm still new to Vue and I need to pass for loop data to a Vue component through Django template, but I don't know exactly how.

In my html page I'm looping a vue component with Django, like this:

{% for employee in object_list %}

<app-card name={{ employee.name }} skills-all={{ employee.skils.all }} skill={{ employee.skils.all.name }}></app-card>

{% endfor %}

Note: skills-all is a list with lists of skills, and I just wanted to loop through all the skills and show all skills names in my html list

And my Vue component looks like this:

<template>
    <div id="card">
        <h1>{{ name }}</h1>
        <ul>
            <li v-for="skill in skillsAll">{{ skill }}</li>
        </ul>
    </div>
</template>

<script>
    export default {
        props: ["name", "skillsAll", "skill"]
    };
</script>

Everything works just fine until I try to make that for loop inside the vue component. Actually I'm very confused about how am I supposed to loop something inside Vue when the data needs to come from outside the component

3
  • I think you have to pass your skills-all data in a javascript compatible way: fatching it from a REST Api endpoint, or loading them with a javascript file inside your html code. I think you can't share this data from your server side template engine (django/jinja2) and your Vue.js client side template system. Is this what you are trying for? Commented Jun 19, 2019 at 16:22
  • @StefanoGiraldi My "name" data is showing normally when I pass it through Django to vue, just like other datas. The issue only happens with more complex data like lists. So I thought if "name" is working fine, "skills-all" should also work, but with the correct way to do it. I just don't know how to pass a list data and loop it inside the Vue component Commented Jun 19, 2019 at 17:27
  • You can try to use JSON to pass object data from Django to Javascript code inside the rendered page. Something like this: sending data as JSON object from Python to Javascript with Jinja Commented Jun 20, 2019 at 6:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.