Skip to content

Commit

Permalink
feature
Browse files Browse the repository at this point in the history
add component event click
  • Loading branch information
mod committed Jun 26, 2020
1 parent 559a50c commit 40f374f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 6 additions & 1 deletion examples/routers/calendar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div>
<Calendar>
<Calendar @on-click="handlerClick">
<template v-slot:default="slotProps">
<ul class="info-list">
<li class="info-item" v-for="(it, index) in newsList[slotProps.date]" :key="index">
Expand All @@ -22,6 +22,11 @@
]
}
}
},
methods: {
handlerClick (value) {
console.log(value, '点击选择日期');
}
}
}
</script>
12 changes: 11 additions & 1 deletion src/components/calendar/calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
<tr v-for="item in trDays" :key="item">
<td :class="[classes + '-content-col']" v-for="(child, dindex) in getRenderDays(item)" :key="dindex">
<span
:class="[classes + '-content-num', selectYear === nowYear && nowMonth === selectMonth && child.day === nowDate ? prefixCls+'-content-num-current' : '']"
:class="[classes + '-content-num', selectYear === nowYear && nowMonth === selectMonth && child.day === nowDate ? prefixCls+'-content-num-current' : '']"
@click="handlerClick(child)"
v-if="child.type === 'now'">
{{zeroFill(child.day)}}
</span>
Expand Down Expand Up @@ -95,6 +96,15 @@ export default {
zeroFill (num) {
return num < 10 ? '0'+num : num;
},
handlerClick (item) {
const {selectYear, selectMonth, format} = this;
const zeroFillMonth = this.zeroFill(selectMonth);
const zeroFillDay = this.zeroFill(item.day);
const time = selectYear + format + zeroFillMonth + format + zeroFillDay;
this.$emit('on-click', {
date: time
})
},
next () {
if( this.selectMonth === 12 ){
this.selectYear = this.selectYear + 1;
Expand Down

0 comments on commit 40f374f

Please sign in to comment.