14 Program to demonstrate Nesting Components using VUE CLI

Steps:

1) $npm install -g vue-cli
2) $vue init webpack-simple my-project
3) $cd my-project
4) $npm install
5) $npm run dev

Program:

App.vue:

<template>
  <div id="app">
    {{ msg }}
    <students></students>   
   </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  }
}
</script>

<style>

</style>



Demo.vue (Create New File):

<template>
    <div>
        <p v-for="student in students">
            {{ student }} 
        </p>    
    </div>
</template>

<script>
export default {

  data () {
    return {
        students: ['Tom', 'John', 'Rob']
    } 
  }
}
</script>

<style>

</style>



main.js:

import Vue from 'vue'
import App from './App.vue'
import Demo from './Demo.vue'

Vue.component('students',Demo);
new Vue({
  el: '#app',
  render: h => h(App)
})



Output:

Nesting Components using VUE CLI



Previous
Next Post »