I am trying to build very simple bootstrap alert component but Iam unable to figure out how to get innerHTML of my custom component.
Code:
Vue.component('my-alert', {
  template: '#vue-alert',
  props: ['type', 'title', 'message'],
  created: function() {        
    this.message = this.innerHTML; // <---- NOT WORKING
  }
});
var vm = new Vue({
  el: 'body'
});
HTML:
<my-alert type="success" title="Important">My Message here.</my-alert>
I want to show the component whatever text is provided in it, in this case it should show My Message here.
Here is example of it
Okay I figured out, I needed to use the <slot></slot>.
<template id="vue-alert">
  <div v-if="show" class="alert alert-{{type}} alert-dismissible" role="alert">
  <button @click="removeAlert" type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span>
  </button>
  <strong>{{title}}!</strong> <slot></slot>
  </div>
</template>
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With