美文网首页
vue element 周期给定默认值及周期范围

vue element 周期给定默认值及周期范围

作者: 远方_8378 | 来源:发表于2019-10-14 09:57 被阅读0次

   html:  <el-form-item label="周期:">

     <el-date-picker v-model="value" type="week" @change="handleGetWeek" format="yyyy 第 WW 周" placeholder="选择周"></el-date-picker>

            <span>( {{this.startDate}}  至  {{ this.endDate }} )</span>

        </el-form-item>

mounted(){ this.value = new Date()  }  // 给定当前日期

methods:{

p (s) {

      return s < 10 ? '0' + s : s

    },

    handleGetWeek () {

      let newTime = this.value.getTime() 

      let day = this.value.getDay()

      let oneDayTime = 24 * 60 * 60 * 1000

      let fromTime = newTime - day * oneDayTime

      let endTime = newTime + (6 - day) * oneDayTime

      let fromDate = new Date(fromTime)

      this.startDate = fromDate.getFullYear() + '-' + this.p((fromDate.getMonth() + 1)) + '-' + this.p(fromDate.getDate())

      let toDate = new Date(endTime)

      this.endDate = toDate.getFullYear() + '-' + this.p((toDate.getMonth() + 1)) + '-' + this.p(toDate.getDate())

    },

}

相关文章

网友评论

      本文标题:vue element 周期给定默认值及周期范围

      本文链接:https://www.haomeiwen.com/subject/wqyeeqtx.html