vuejs-渲染类

时间:2019-12-10 09:30:13

标签: javascript vue.js iview

这是我的iview Message函数,用于呈现弹出消息。

    this.$Message.info({
                render: h => {
                    return h('div', {class:"red"}, [
                        'This is created by ',
                        h('span', 'render'),
                        ' function'
                    ])
                }
            });

CSS

.red{
  color:red;
  background:blue;
}

但是,我需要为span而不是整个div渲染一个类。

仅渲染span的任何方法吗?

1 个答案:

答案 0 :(得分:1)

class对象而不是span元素放在div元素中。

this.$Message.info({
  render: h => {
    return h("div", 
    [
      "This is created by ", 
      h("span", {class : "red" }, "render function ")
    ])
  }
});

示例:

Vue.config.devtools = false;
Vue.config.productionTip = false;

var app = new Vue({
  el: '#app',
  render: h => {
    return h("div", 
    [
      "This is created by ", 
      h("span", {class : "red" }, "render function ")
    ])
  }
})
.red {
  color:red;
  background:blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.16/vue.js"></script>

<div id="app">
</div>