首页 > 解决方案 > 如何将`item-text`与vue渲染功能绑定

问题描述

我正在尝试使用ONLYrender函数呈现 Vue 模板。

在这种情况下,我试图绑定item-text属性对象......但我的尝试失败了。

new Vue({
  el: "#app",
  data: () => ({
    items: [
      { color: "blue", hash: "#42A5F5" },
      { color: "green", hash: "#FF4081" },
      { color: "red", hash: "#FF5252" },
      { color: "yellow", hash: "#5E35B1" }
    ]
  }),
  render: function(h) {
    return h("v-app", { attrs: { dark: "dark" } }, [
      h("v-container", [
        h("v-select", { attrs: {
          'items': this.items 
          'item-text' : color // doesn't work  color is undefined
          }
        })   
      ])
     ])
    }
  })

那么,有没有办法只使用该功能来做到这一点render

密码笔

标签: vue.jsvuetify.js

解决方案


使用函数将项目对象映射到颜色字符串。

h('v-select',{attrs : {'items' : this.items, 'item-text': it=>it.color }}),

推荐阅读