mirror of
https://github.com/youzan/vant.git
synced 2025-10-19 18:14:13 +00:00
Checkbox: support different shape
This commit is contained in:
@@ -1,39 +1,46 @@
|
||||
<template>
|
||||
<div
|
||||
class="van-checkbox"
|
||||
:class="{
|
||||
:class="[
|
||||
'van-checkbox',
|
||||
`van-checkbox--${shape}`, {
|
||||
'van-checkbox--disabled': isDisabled
|
||||
}">
|
||||
}]">
|
||||
<span class="van-checkbox__input">
|
||||
<input
|
||||
v-model="currentValue"
|
||||
type="checkbox"
|
||||
class="van-checkbox__control"
|
||||
:disabled="isDisabled">
|
||||
<span class="van-icon" :class="{
|
||||
'van-icon-checked': isChecked,
|
||||
'van-icon-check': !isChecked
|
||||
}">
|
||||
</span>
|
||||
:disabled="isDisabled"
|
||||
/>
|
||||
<van-icon name="success" />
|
||||
</span>
|
||||
<span class="van-checkbox__label" @click="handleLabelClick">
|
||||
<span class="van-checkbox__label" @click="onClickLabel">
|
||||
<slot></slot>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Icon from '../Icon';
|
||||
import findParent from '../mixins/findParent';
|
||||
|
||||
export default {
|
||||
name: 'van-checkbox',
|
||||
|
||||
components: {
|
||||
[Icon.name]: Icon
|
||||
},
|
||||
|
||||
mixins: [findParent],
|
||||
|
||||
props: {
|
||||
value: {},
|
||||
disabled: Boolean,
|
||||
name: [String, Number]
|
||||
name: [String, Number],
|
||||
shape: {
|
||||
type: String,
|
||||
default: 'round'
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
@@ -78,6 +85,7 @@ export default {
|
||||
|
||||
isChecked() {
|
||||
const currentValue = this.currentValue;
|
||||
console.log('this.currentValue:', this.currentValue);
|
||||
if ({}.toString.call(currentValue) === '[object Boolean]') {
|
||||
return currentValue;
|
||||
} else if (currentValue !== null && currentValue !== undefined) {
|
||||
@@ -93,7 +101,7 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
handleLabelClick() {
|
||||
onClickLabel() {
|
||||
if (this.isDisabled) {
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user