0

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?

2 Answers 2

1

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>

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I need to apply the css for the word in the span only , instead of the whole sentence
0

class should be an array, not a string:

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

Vue docs

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.