VueJS props are undefined in component

Viewed 18950

I am trying to integrate VueJS with my frontend for my Django applications. I have the following Vue code in a javascript file:

window.onload = function() {
    Vue.component('discuss-post', {
        props: ['post'],
        template:  `<div class="card">
                        <div class="grid-x margin-x">
                            <div class="cell small-4">
                                <img class="avatar-img" :src="post.by.profile.img_url">
                                <p style="font-family: Abel;font-size: 24px">{{ post.by }}</p>
                            </<div>
                        </div>
                        <div class="grid-x margin-x">
                            <div class="cell small-4">
                                <p style="font-family: Abel;font-size: 18px">{{ post.content }}</p>
                            </div>
                        </div>
                    </div>`
    })
    var postDiv = new Vue({
        el: "#post-div"
    })
}

And the following code in an HTML file:

            <div class="card-section">
                {% for feed in feeds %}
                {% for post in feed %}
                <div id="post-div">
                    <discuss-post post="{{ post }}"></discuss-post>
                </div>
                {% endfor %}
                {% endfor %}
            </div>

However, when I load my page I get these errors in my console:

enter image description here

What in my code could be causing these errors to be raised?

3 Answers

For compiling template error remove/fix this tag:</<div>. Also, you have to pass props to the subcomponent like this:

<discuss-post :post="post"></discuss-post>

For your profile value error, you have to check your JSON structure in data.

See the following example:

Vue.component('discuss-post', {
  props: ['post'],
  template: `<div class="card">
                     <div class="grid-x margin-x">
                       <div class="cell small-4">
                         <img class="avatar-img" :src="post.by.profile.img_url" />
                         <p style="font-family: Abel;font-size: 24px">{{ post.by }}</p>
                       <div>
                     </div>
               <div class="grid-x margin-x">
                 <div class="cell small-4">
                   <p style="font-family: Abel;font-size: 18px">{{ post.content }}</p>
                 </div>
               </div>
          </div>`
})
var postDiv = new Vue({
  el: "#post-div",
  data: function() {
    return {
      post: {
        content: "Post Content",
        by: {
          profile: {
            img_url: "http://www.gstatic.com/webp/gallery/1.jpg"
          }
        }
      }
    }
  }
})
<script src="https://vuejs.org/js/vue.min.js"></script>
<div class="card-section">
  <div id="post-div">
    <discuss-post :post="post"></discuss-post>
  </div>
</div>

Related