Vuejs :is example

In this example below you will see how to do a Vuejs :is example with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by ColdToast, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright ColdToast ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Vuejs :is example</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
  
  
</head>

<body>

  <div id="example">
  <a-component 
    name="Mike"
  ></a-component>
  
  <b-component></b-component>
  
  <component 
    :is="activeControl" 
    name="Not Mike"
  ></component>
  
  <button @click="activeControl = 'b-component'">Click me</button>
</div>
  <script src='https://cdnjs.cloudflare.com/ajax/libs/vue/2.3.4/vue.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/ColdToast/vuejs-is-example-MENNGZ */
// register
Vue.component('a-component', {
  template: '<div>{{name}} does this work?</div>',
  props: {
    'name': {
      type: String,
      required: true
    }
  }
});

Vue.component('b-component', {
  template: '<div>B component!</div>'
});

// create a root instance
new Vue({
  el: '#example',
  data: function data() {
    return {
      activeControl: 'a-component'
    };
  }
});

Comments