update Checkbox

when use Checkbox single, can hide default slot
This commit is contained in:
梁灏 2017-03-15 18:52:33 +08:00
parent 67f4d8e763
commit 7c2ed52c61
2 changed files with 38 additions and 3 deletions

View file

@ -11,6 +11,13 @@
<Form-item prop="user">
<Input v-model="formInline.user"></Input>
</Form-item>
<Form-item>
<Transfer
:data="formInline.data1"
:target-keys="formInline.targetKeys1"
:render-format="render1"
@on-change="handleChange1"></Transfer>
</Form-item>
<Form-item>
<i-button type="primary" @click.native="handleSubmit('formInline')">登录</i-button>
</Form-item>
@ -22,6 +29,8 @@
data () {
return {
formInline: {
data1: this.getMockData(),
targetKeys1: this.getTargetKeys(),
date: new Date(),
user: '',
value2: [],
@ -118,6 +127,32 @@
},
handleInput (val) {
console.log(val)
},
getMockData () {
let mockData = [];
for (let i = 1; i <= 20; i++) {
mockData.push({
key: i.toString(),
label: '内容' + i,
description: '内容' + i + '的描述信息',
disabled: Math.random() * 3 < 1
});
}
return mockData;
},
getTargetKeys () {
return this.getMockData()
.filter(() => Math.random() * 2 > 1)
.map(item => item.key);
},
render1 (item) {
return item.label;
},
handleChange1 (newTargetKeys, direction, moveKeys) {
console.log(newTargetKeys);
console.log(direction);
console.log(moveKeys);
this.formInline.targetKeys1 = newTargetKeys;
}
}
}

View file

@ -18,7 +18,7 @@
:checked="currentValue"
@change="change">
</span>
<slot v-if="showSlot"><span ref="slot">{{ label }}</span></slot>
<slot><span v-if="showSlot">{{ label }}</span></slot>
</label>
</template>
<script>
@ -89,7 +89,7 @@
if (this.parent) this.group = true;
if (!this.group) {
this.updateModel();
this.showSlot = this.$slots.default === undefined;
this.showSlot = this.$slots.default !== undefined;
}
},
methods: {
@ -103,7 +103,7 @@
this.$emit('input', checked);
if (this.group) {
this.parent.change(this.model);
this.$parent.change(this.model);
} else {
this.$emit('on-change', checked);
this.dispatch('FormItem', 'on-form-change', checked);