This article example shares the specific code of Vue to achieve the price calendar effect for your reference. The specific content is as follows 1. Rendering 2. Download and install globally: npm install ele-calendar 3. Create a new file calendar.vue under components, with the following content: <template> <div style="width:600px"> <ele-calendar :render-content="renderContent" :data="datedef" :prop="prop" :disabledDate="disabledDate" :effectiveTimeLimit="effectiveTimeLimit" :defaultValue="defaultValue" > </ele-calendar> </div> </template> <script> import eleCalendar from 'ele-calendar' import 'ele-calendar/dist/vue-calendar.css' export default { props: { datedef: { type: Array, default: () => { return [] } }, defaultPrice: { type: String, default: () => { return '' } }, effectiveTimeLimit: type: String, default: () => { return '' } }, defaultValue: { type: Date, default: () => { return new Date() } } }, data () { const self = this return { prop: 'date', // Corresponding date field name disabledDate: date => { return ( date.valueOf() < new Date().valueOf() - 1 * 24 * 60 * 60 * 1000 || date.valueOf() > new Date(self.effectiveTimeLimit).valueOf() ) } } }, components: eleCalendar }, methods: { //JSX syntax renderContent (h, parmas) { const self = this const loop = data => { return ( <div class={data.defvalue.value ? 'active' : ''}> <div>{data.defvalue.text}</div> <div> ¥ <i-input value={ data.defvalue.value.content ? data.defvalue.value.content : self.defaultPrice } on-on-blur={event => self.handleChange( event, data.defvalue.value ? data.defvalue.value.date : self.handleDate(data.defdate) ) } disabled={ data.defvalue.value ? new Date(data.defvalue.value.date).valueOf() < new Date().valueOf() - 1 * 24 * 60 * 60 * 1000 || new Date(data.defvalue.value.date).valueOf() > new Date(self.effectiveTimeLimit).valueOf() : data.defdate.valueOf() < new Date().valueOf() - 1 * 24 * 60 * 60 * 1000 || data.defdate.valueOf() > new Date(self.effectiveTimeLimit).valueOf() } key={ data.defvalue.value ? data.defvalue.value.date : self.handleDate(data.defdate) } /> </div> </div> ) } return <div style='min-height:60px;'>{loop(parmas)}</div> }, handleChange (event, date) { console.log(event, date, 'dddddd') const self = this const index = self.datedef.findIndex(item => { return item.date === date }) if (isNaN(event.target.value)) { self.$Message.error('Please enter the correct price') event.target.value = self.defaultPrice return } if (event.target.value && index === -1) { if (event.target.value === self.defaultPrice) { return } self.datedef.push({ date, content: event.target.value, cid: null }) console.log('self.datedef', self.datedef) this.$emit('aaa', self.datedef) } else if (event.target.value && index !== -1) { if (event.target.value === self.defaultPrice) { self.datedef.splice(index, 1) return } const selectItem = self.datedef[index] selectItem.content = event.target.value self.datedef.splice(index, 1, selectItem) } else if (!event.target.value && index !== -1) { self.datedef.splice(index, 1) } else { event.target.value = self.defaultPrice } }, handleDate (date) { const year = date.getFullYear() let month = date.getMonth() + 1 month = month >= 10 ? month : '0' + month let idate = date.getDate() idate = idate >= 10 ? idate : '0' + idate return `${year}-${month}-${idate}` } } } </script> <style lang="scss"> .el-picker-panel-calendar.el-date-picker-calendar.el-popper { box-shadow: none; } .el-date-table-calendar td > div > div { border: 1px solid #aaa; color: #fff; margin: 5px; & > div:first-child { background-color: #aaa; } & > div:nth-child(2) { padding: 5px; color: #000; .ivu-input-wrapper { width: 80%; } } &.active { border: 1px solid #2ab561; & > div:first-child { background-color: #2ab561; } & > div:nth-child(2) { padding: 5px; color: #000; .ivu-input-wrapper { width: 80%; } } } } // If this section is released, all boxes before the current day will be grayed out // .el-date-table-calendar td.disabled > div > div { // border: 1px solid #aaa; //color: #fff; //margin: 5px; // & > div:first-child { // background-color: #aaa; // } // & > div:nth-child(2) { // padding: 5px; //color: #000; // .ivu-input-wrapper { // width: 80%; // } // } // } .el-date-table-calendar td.available:hover { color: #000; } .el-date-table-calendar td.available.today { color: #000; font-weight: normal; } .el-date-table-calendar tr td.current.available:not(.disabled) { background-color: #fff; } </style> 4. Page introduction registration <script> import calendar from '../../components/calendar' export default { components: { calendar } } data() { return { effectiveTimeLimit: '', ruleForm: { price: '', configPriceList: [] } }, rules: } } } </script> 5.html I wrote it in the dialog <el-form-item label="Price settings" prop="calendarPrice"> <calendar :datedef="ruleForm.configPriceList" :default-price="ruleForm.price" :effectiveTimeLimit="effectiveTimeLimit" ></calendar> </el-form-item> The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Mysql stores tree structure through Adjacency List (adjacency list)
>>: How to start and stop SpringBoot jar program deployment shell script in Linux
Table property settings that work well: Copy code ...
Table of contents 1. When the mouse passes over t...
Table of contents 1. Background 2. Slow query cau...
Sometimes it is slow to download large network fi...
What is a profile? We can use it when we want to ...
First, take a look at Alibaba Cloud's officia...
This article example shares the specific code of ...
Table of contents Brief summary At noon today, th...
Introduction The Docker community has created man...
In the database, both UNION and UNION ALL keyword...
In a complex table structure, some cells span mul...
1- Styling dropdown select boxes - Modify the dro...
Recently, I want to build a hadoop test cluster i...
Table of contents 1. Introduction 2. Understand t...
This article shares the specific code of a simple...