Vue

by Ico Dimchev

HTML

<div id="app">
  <button @click="changeTemplate">Change template</button>
  <Dynamo :template="template" />
</div>

CSS

body {
  background: #20262E;
  padding: 20px;
  font-family: Helvetica;
}

#app {
  background: #fff;
  border-radius: 4px;
  padding: 20px;
  transition: all 0.2s;
}

li {
  margin: 8px 0;
}

h2 {
  font-weight: bold;
  margin-bottom: 15px;
}

del {
  color: rgba(0, 0, 0, 0.3);
}

.card{
  margin: 10px auto;
  padding: 10px;
  background: lightgrey;
}

Vue

Vue.component('Card', {
	name: 'Card',
	template: '<div class="card"><slot></slot></div>'
});

Vue.component('Dynamo', {
	functional: true,
  props: ['template'],
  render: function(createElement, context){
  	var template =  '<div class="dynamo">' + context.props.template + '</div>';
  	return createElement({template: template});
  }
});

new Vue({
  el: "#app",
  data: function(){
  	return {
    template: 'Nothing fancy'
    }
  },
  methods: {
  	changeTemplate: function(){
    this.template = '<p>Paragraph and <p><div is="Card">Card</div>';
    }
  }
})