hatched
hatched

Reputation: 865

vuejs - rendering class

This is my iview Message function that renders popup message.

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

The CSS

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

However, I need to render a class for the span instead of the whole div.

Any ways to render only the span?

Upvotes: 0

Views: 407

Answers (2)

jarraga
jarraga

Reputation: 437

class should be an array, not a string:

h('div', {class: ['red']})

Vue docs

Upvotes: 0

Pierre Said
Pierre Said

Reputation: 3820

Put the class object in the span element instead of the div element.

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

Example :

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>

Upvotes: 1

Related Questions