Element: jsx对el-checkbox-group下的el-checkbox进行渲染时,生成的checkbox无法选中

Created on 16 Mar 2017  ·  4Comments  ·  Source: ElemeFE/element

根据 babel-plugin-transform-vue-jsx文档,代码如下

methods: {
    sync(prop, value) {
         this[prop] = value;
    }
},
render(h) {
    const checkboxes = this.data.map((item) => {
        return <el-checkbox label={this.item}></el-checkbox>
    });
    return (
        <el-checkbox-group on-input={(e) => this.sync('checkList', e.target.value)} >
            {checkboxes}
        </el-checkbox-group>
    )
}

生成后点击checkbox提示prop 'value' is not defined

Most helpful comment

render(h) {
  const data = ['选项1', '选项2', '选项3'];
  const checkboxes = data.map(item => {
    return <el-checkbox label={item}></el-checkbox>;
  });
  return (
    <el-checkbox-group value={this.value} on-input={this.sync}>
      {checkboxes}
    </el-checkbox-group>
  );
},

data() {
  value: []
},

methods: {
  sync(e) {
    this.value = e;
  }
}

All 4 comments

(e) => this.sync('checkList', e.target.value)
e 并不是一个 DOM 事件,所以不存在 e.target.value。你可以打印看看 e 是什么。

e只是单纯的true值。我是看jsx的文档中说不支持v-model,需要按照这样的写法来获取的。
但是如果在el-checkbox-group 这里直接写v-model={this.checkList} 同样没有效果。
v-model绑定group,checkbox里绑定label值这样的数组渲染可否提供下demo呢,谢谢

render(h) {
  const data = ['选项1', '选项2', '选项3'];
  const checkboxes = data.map(item => {
    return <el-checkbox label={item}></el-checkbox>;
  });
  return (
    <el-checkbox-group value={this.value} on-input={this.sync}>
      {checkboxes}
    </el-checkbox-group>
  );
},

data() {
  value: []
},

methods: {
  sync(e) {
    this.value = e;
  }
}

解决了,非常感谢!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranzSkuffka picture FranzSkuffka  ·  3Comments

yorululu picture yorululu  ·  3Comments

makunsusu picture makunsusu  ·  3Comments

fscardua picture fscardua  ·  3Comments

akaylh picture akaylh  ·  3Comments