当前位置: 首页 > Web前端 > vue.js

layui的laydate是动态改变mark值的,change方法无效,解决方案

时间:2023-03-31 19:00:47 vue.js

使用laydate的mark标签时,切换时间改变时,mark值不能及时更新。官方的change事件总是在页面挂载后调用,导致数据没有及时更新。于是在网上找了解决办法,有位大神给出了添加beforechange事件的解决方法:第一步:修改laydate.js。有两个地方需要修改。1.找到T.prototype.change事件,添加return替换为return{prevYear:function(){s("sub")||(a.year--,n.range||t.done(null,"beforeChange"),t.checkDate("limit").calendar(),n.range||t.done(null,"change"))},prevMonth:function(){vare=t.getAsYM(a.year,a.month,"sub");w.extend(a,{年:e[0],月:e[1]}),n.range||t.done(null,"beforeChange"),t.checkDate("limit").calendar(),n.range||t.done(null,"change")},nextMonth:function(){vare=t.getAsYM(a.year,a.month);w.extend(a,{年:e[0],月:e[1]}),n.range||t.done(null,"beforeChange"),t.checkDate("limit").日历(),n.range||t.done(null,"change")},nextYear:function(){s()||复制代码(a.year++,n.range||t.done(null,"beforeChange"),t.ccheckDate("limit").calendar(),n.range||t.done(null,"change"))}}2.找到T.prototype.list,把n.range||n.done(null,"change")语句的前一段改为:"year"===a.type||“月”===a.type?(w(d).find("."+o).removeClass(o),w(this).addClass(o),"month"===a.type&&"year"===e&&(n.listYM[t][0]=r,l&&(n[["startDate","endDate"][t]].year=r),n.list("month",t))):(n.range||n.done(null,"beforeChange"),n.checkDate("limit").calendar(),n.closeList()),n.setBtnStatus(),step2:直接在js中使用beforeChangelaydate.render({elem:'#test18',trigger:'click',mark:{},beforeChange:function(value,date,endDate){//console.log('beforeChange')})}但是我遇到了另一个问题,就是切换月份后,关闭后没有重新选择日期,再次点击显示日期,当前选择月份的标记没有渲染,是空的,经过一番查找,终于通过更改方法,更改:function(value,date,endDate){console.log('change');setMonthDate(this.value);},完成:函数(值,日期){控制台。日志('完成');设定星期一thDate(value);}functionsetMonthDate(value){//Ajax实时获取数据并重置标记值varobj={};console.log(obj)myLaydate.config.mark=obj;}————————————————