首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >VueJS :获取自定义组件的innerHTML

VueJS :获取自定义组件的innerHTML
EN

Stack Overflow用户
提问于 2016-08-20 23:52:05
回答 1查看 5.1K关注 0票数 6

我试图建立非常简单的引导警报组件,但我无法弄清楚如何获得我的自定义组件的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'
});

HTML:

<my-alert type="success" title="Important">My Message here.</my-alert>

我希望显示组件中提供的任何文本,在本例中,它应该显示My Message here.

Here is example of it

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-08-21 00:35:21

好吧,我想好了,我需要使用。

<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>
票数 8
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39056039

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档