VueJS:获取自定义组件的innerHTML

dev*_*v02 4 html javascript vue.js

我正在尝试构建非常简单的引导程序警报组件,但我无法弄清楚如何获取innerHTML我的自定义组件.

码:

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'
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<my-alert type="success" title="Important">My Message here.</my-alert>
Run Code Online (Sandbox Code Playgroud)

我想显示组件中提供的任何文本,在这种情况下它应该显示 My Message here.

这是它的例子

dev*_*v02 6

好吧,我想通了,我需要使用<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">&times;</span>
  </button>
  <strong>{{title}}!</strong> <slot></slot>
  </div>
</template>
Run Code Online (Sandbox Code Playgroud)