feat(Calendar): add select event

This commit is contained in:
陈嘉涵 2019-12-24 16:31:32 +08:00 committed by neverland
parent 43a0aed8c9
commit c447152be9
4 changed files with 22 additions and 9 deletions

View File

@ -24,17 +24,21 @@ Vue.use(Calendar);
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|------|------|------|------|------|
| v-model | 选中的日期 | `Date` | - | - |
| type | 选择类型,`single`为选择单日,`range`为选择日期区间 | `string` | `single` | - |
| title | 日历标题 | `string` | - | - |
| min-date | 最小日期 | `Date` | 当前时间 | - |
| max-date | 最大日期 | `Date` | 当前时间的六个月后 | - |
### Events
| 事件名 | 说明 | 回调参数 |
|------|------|------|
| select | 选择日期时触发 | value: Date |
### Slots
| 名称 | 说明 | SlotProps |
|------|------|------|
| 名称 | 说明 |
|------|------|
### 方法

View File

@ -3,18 +3,18 @@
<demo-block :title="$t('basicUsage')">
<van-cell
:title="$t('selectDate')"
:value="formatDate(date.selectDate)"
is-link
@click="toggle('selectDate', true)"
/>
</demo-block>
<van-popup
v-model="show.selectDate"
round
closeable
position="bottom"
>
<van-calendar v-model="date.selectDate" :title="$t('title')" />
<van-popup v-model="show.selectDate" round closeable position="bottom">
<van-calendar
v-model="date.selectDate"
:title="$t('title')"
@select="show.selectDate = false"
/>
</van-popup>
</demo-section>
</template>
@ -46,6 +46,12 @@ export default {
methods: {
toggle(type, show) {
this.show[type] = show;
},
formatDate(date) {
if (date) {
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
}
}
}
};

View File

@ -172,6 +172,7 @@ export default createComponent({
if (this.type === 'single') {
this.$emit('input', item.date);
this.$emit('select', item.date);
}
}
},

View File

@ -76,9 +76,11 @@
width: 14.285%;
height: 64px;
font-size: @font-size-lg;
cursor: pointer;
&--disabled {
color: @gray-5;
cursor: default;
}
}