当前位置: 首页 > 工具软件 > e-Calendar > 使用案例 >

vue 日期默认显示_怎么设置vue-mobile-calendar的默认值怎么设置?

邢寒
2023-12-01

vue组件中引用了日期选择组件,里面有配置默认选择当前日期的参数defaultDate,默认显示当天日期,现在我想实现任何一个日期从父组件带过来,把当前默认选中的日期换成父组件带过来的日期,现在日期带过了了,格式转化也没有问题,就是当前的默认选中日期始终改变不了,求大神指教

html如下

:defaultDate="defaultDate"

@change="handelChange">

js如下

export default {

name: "Afterpat",

data () {

return {

defaultDate:new Date(),

calendarShow: true,

minDate: new Date('2010/1/1'),

maxDate: new Date('2040/1/1'),

month: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],

week:["周一", "周二", "周三", "周四", "周五", "周六", "周日"],

closeByClickmask: false,

rangeHours: 0,

rangeMinutes: 0,

value:0,

timeHour:'',

timeMinutes: '',

dateValue: '',

// curDate: this.dateSelect

}

},

watch:{

rangeHours(val) {

if(parseInt(val/(100/24))<10) {

// this.rangeHours = parseInt('0') + parseInt(val/(100/24))

console.log(this.rangeHours)

}

},

rangeMinutes(val) {

if(parseInt(val/(100/60))<10) {

// this.rangeMinutes = '0' +parseInt(val/(100/60) ).toString()

}

},

// dateSelect(val){

// // alert(val)

// this.defaultDate = val

// console.log(this.defaultDate)

// }

},

mounted(){

},

methods: {

onChange(value) {

// console.log(value)

},

onChangeTwo(value) {

// console.log(value)

},

formatDate(date) {

const y = date.getFullYear()

let m = date.getMonth() + 1

m = m < 10 ? '0' + m : m

let d = date.getDate()

d = d < 10 ? ('0' + d) : d

let h = date.getHours()

h = h <10 ? ('0'+h):h

let min = date.getMinutes()

min = min < 10?('0' + min):min

let s = date.getSeconds()

s = s<10?('0'+s):s

return y + '-' + m + '-' + d + ' '

},

handelChange(date){

// this.calendarShow = true

this.dateValue = this.formatDate(date)

// var date = this.formatDate(date)

// this.$emit('timeSelect', data)

this.closeByClickmask = false

},

confirm(){

// this.calendarShow = true

var date = ''

var isStop = false

var defaultDate = this.formatDate(new Date())

if(this.dateValue && defaultDate) {

date = this.dateValue

} else {

date = defaultDate

}

if(parseInt(this.rangeHours/(100/24) )<10) {

this.timeHour = '0' + parseInt(this.rangeHours/(100/24) ).toString()

} else {

this.timeHour = parseInt(this.rangeHours/(100/24) ).toString()

}

if(parseInt(this.rangeMinutes/(100/60))<10) {

this.timeMinutes = '0' + parseInt(this.rangeMinutes/(100/60)).toString()

} else if(parseInt(this.rangeMinutes/(100/60)) == 60) {

this.timeMinutes = '00'

} else {

this.timeMinutes = parseInt(this.rangeMinutes/(100/60)).toString()

}

let data = {}

if(this.hasDate == 'none') {

data = {

isShow: false,

time:date

}

} else {

data = {

isShow: false,

time:date + '' + this.timeHour + ':' + this.timeMinutes

}

}

this.$emit('timeSelect', data)

}

},

computed: {

},

components:{

Range

},

created(){

// if(this.dateSelect) {

// this.defaultDate = this.dateSelect

// } else {

// this.defaultDate = new Date()

// }

if(!sessionStorage.getItem('openId')) {//android系统下进入悬浮框重载页面,之前session存入的openid已不存在,此时重新获取微信授权

var href=window.location.href

this.base.wxinit(href)

}

this.base.getWxOpenid()

},

props: {

hasDate: {

type: String,

default () {

return ''

}

},

type: {

type: String,

default () {

return ''

}

},

// dateSelect: {

// type: Date,

// default () {

// return new Date()

// }

// }

}

}

 类似资料: