代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<style type="text/css">
.el-date-editor.el-input, .el-date-editor.el-input__inner{
width: 360px;
}
</style>
</head>
<body>
<div id="app">
<div class="block">
<span class="demonstration">周</span>
<el-date-picker @change="changeOne" v-model="value1" type="week" :format="startTimeStamp + ' 至 ' + endTimeStamp" placeholder="选择周">
</el-date-picker>
</div>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
new Vue({
el: '#app',
data() {
return {
value1: "",
startTimeStamp:"",
endTimeStamp:""
}
},
methods: {
changeOne(val) {
let timeStamp = val.getTime();
this.startTimeStamp = this.fun(timeStamp - 24 * 60 * 60 * 1000);
this.endTimeStamp = this.fun(timeStamp + (24 * 60 * 60 * 1000) * 5);
console.log(this.startTimeStamp, this.endTimeStamp);
},
fun(unixtimestamp) {
var unixtimestamp = new Date(unixtimestamp);
var year = 1900 + unixtimestamp.getYear();
var month = "0" + (unixtimestamp.getMonth() + 1);
var date = "0" + unixtimestamp.getDate();
var hour = "0" + unixtimestamp.getHours();
var minute = "0" + unixtimestamp.getMinutes();
var second = "0" + unixtimestamp.getSeconds();
return year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date
.length) +
" " + hour.substring(hour.length - 2, hour.length) + ":" +
minute.substring(minute.length - 2, minute.length) + ":" +
second.substring(second.length - 2, second.length);
}
}
})
</script>
</html>