fix radio dynamic init bug (#1514)

This commit is contained in:
baiyaaaaa 2016-12-02 17:35:54 +08:00 committed by cinwell.li
parent d3afe22e89
commit e56f52ff26
5 changed files with 50 additions and 51 deletions

View File

@ -103,12 +103,6 @@
falseLabel: [String, Number]
},
data() {
return {
isGroup: false
};
},
methods: {
addToStore() {
if (Array.isArray(this.model)) {

View File

@ -3,33 +3,39 @@
name: 'ElRadioButton',
props: {
label: {
type: [String, Number],
required: true
},
label: {},
disabled: Boolean,
name: String
},
data() {
return {
size: this.$parent.size
};
},
computed: {
value: {
get() {
return this.$parent.value;
return this._radioGroup.value;
},
set(newValue) {
this.$parent.$emit('input', newValue);
set(value) {
this._radioGroup.$emit('input', value);
}
},
_radioGroup() {
let parent = this.$parent;
while (parent) {
if (parent.$options.componentName !== 'ElRadioGroup') {
parent = parent.$parent;
} else {
return parent;
}
}
return false;
},
activeStyle() {
return {
backgroundColor: this.$parent.fill,
borderColor: this.$parent.fill,
color: this.$parent.textColor
backgroundColor: this._radioGroup.fill,
borderColor: this._radioGroup.fill,
color: this._radioGroup.textColor
};
},
size() {
return this._radioGroup.size;
}
}
};

View File

@ -23,12 +23,8 @@
watch: {
value(value) {
this.$emit('change', value);
this.broadcast('ElRadio', 'initData', value);
this.dispatch('ElFormItem', 'el.form.change', [this.value]);
}
},
mounted() {
this.broadcast('ElRadio', 'initData', this.value);
}
};
</script>

View File

@ -4,14 +4,14 @@
<span class="el-radio__inner"
:class="{
'is-disabled': disabled,
'is-checked': store === label,
'is-checked': model === label,
'is-focus': focus
}"></span>
<input
class="el-radio__original"
:value="label"
type="radio"
v-model="store"
v-model="model"
@focus="focus = true"
@blur="focus = false"
:name="name"
@ -34,42 +34,45 @@
componentName: 'ElRadio',
props: {
value: [String, Number],
label: {
type: [String, Number],
required: true
},
value: {},
label: {},
disabled: Boolean,
name: String
},
data() {
return {
focus: false,
isGroup: false,
store: this.value
focus: false
};
},
watch: {
store(store) {
if (this.isGroup) {
this.dispatch('ElRadioGroup', 'input', store);
} else {
this.$emit('input', store);
computed: {
isGroup() {
let parent = this.$parent;
while (parent) {
if (parent.$options.componentName !== 'ElRadioGroup') {
parent = parent.$parent;
} else {
this._radioGroup = parent;
return true;
}
}
return false;
},
value(val) {
this.store = val;
}
},
model: {
get() {
return this.isGroup ? this._radioGroup.value : this.value;
},
created() {
this.$on('initData', data => {
this.store = data;
this.isGroup = true;
});
set(val) {
if (this.isGroup) {
this.dispatch('ElRadioGroup', 'input', [val]);
} else {
this.$emit('input', val);
}
}
}
}
};
</script>

View File

@ -4,7 +4,7 @@ Function.prototype.bind = require('function-bind');
require('packages/theme-default/src/index.css');
// require all test files (files that ends with .spec.js)
const testsContext = require.context('./specs', true, /tabs\.spec$/);
const testsContext = require.context('./specs', true, /\.spec$/);
testsContext.keys().forEach(testsContext);
// require all src files except main.js for coverage.