javascript - vuejs - 渲染类

标签 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吗?

最佳答案

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>

关于javascript - vuejs - 渲染类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59264047/

相关文章:

javascript - document.getElementById 方法在哪里定义?

vue.js - 如何在 NuxtJS 中的链接访问时刷新整个页面?

html - 将插槽传递到 Vue.js 中的插槽

vue.js - 从 Array JS vue 中获取值

javascript - Vue动态组件: how to select from multiple instance of the same component

python - 如何从 "i view X"打开使用 "SMI"系统创建的 *.idf 眼动仪数据

javascript - Knockout JS - 数据绑定(bind)多个值

Javascript:将字符串解释为对象引用?

javascript - 有任何想法吗?鼠标进入/鼠标离开(我被卡住了)