DEV Community

Margaret W.N
Margaret W.N

Posted on • Edited on

3 1

Day 81: My Vue Component

I made a component in Vue that does nothing important. The steps in summarry:

  • Created an Vue instance in index.js
new Vue({
  el: '#app',
  data: {
    days: ['Mon', 'Tue', 'Wed', 'Thur']
  }
});
Enter fullscreen mode Exit fullscreen mode
  • Defined a component in index.js
Vue.component('card', {})
Enter fullscreen mode Exit fullscreen mode

Side note: Single word component names are not a good practice.

  • Defined a template in index.html
<script type="text/x-template" id="card-template" >
  <div class="card">
    <p id="nextDay"> {{day}} </p>
    <div class="innerCard"></div>
  </div>
</script>
Enter fullscreen mode Exit fullscreen mode
  • Used a CSS selector to access the template in index.js
Vue.component('card', {
template:'#card-template'
})
Enter fullscreen mode Exit fullscreen mode
  • Created a prop in index.js
 props: {
    day: { 
      type: String,
      required: true
    }
  }
Enter fullscreen mode Exit fullscreen mode
  • Looped through the data in the Vue instance in index.html
  <div id="app"> 
    <card v-for="day in days" :day="day"> 
    </card>
  </div>
Enter fullscreen mode Exit fullscreen mode

Output
Alt Text

Day 81 Done and dusted

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay