File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 9
9
<div class =" container" >
10
10
<h3 >Example2: Treat a value as a Date Object</h3 >
11
11
<input type =" date"
12
- v-bind:value =" date2"
12
+ v-bind:value =" dateToStr( date2) "
13
13
v-on:input =" date2 = strToDate($event.target.value)"
14
14
/>
15
15
<p >{{ date2 }}</p >
@@ -36,8 +36,16 @@ export default class App extends Vue {
36
36
private date2: Date = new Date ();
37
37
private date3: Date = new Date ();
38
38
39
- strToDate(date : string ): Date {
40
- return new Date (date );
39
+ strToDate(str : string ): Date {
40
+ return new Date (str );
41
+ }
42
+
43
+ dateToStr(date : Date ): string {
44
+ const year = date .getFullYear ();
45
+ const month = date .getMonth () + 1 < 9 ? ` 0${date .getMonth () + 1 } ` : ` ${date .getMonth () + 1 } ` ;
46
+ const day = date .getDate () < 9 ? ` 0${date .getDate ()} ` : ` ${date .getDate ()} ` ;
47
+ const strDate = ` ${year }-${month }-${day } ` ;
48
+ return strDate ;
41
49
}
42
50
}
43
51
</script >
Original file line number Diff line number Diff line change 1
1
<template >
2
2
<div >
3
3
<input type =" date"
4
- v-bind = " date"
4
+ v-bind:value = " dateToStr( date) "
5
5
v-on:input =" date = strToDate($event.target.value)"
6
6
/>
7
7
<p >{{ date }}</p >
@@ -19,6 +19,14 @@ class MyDate extends Vue {
19
19
private strToDate(str : string ): Date {
20
20
return new Date (str );
21
21
}
22
+
23
+ private dateToStr(date : Date ): string {
24
+ const year = date .getFullYear ();
25
+ const month = date .getMonth () + 1 < 9 ? ` 0${date .getMonth () + 1 } ` : ` ${date .getMonth () + 1 } ` ;
26
+ const day = date .getDate () < 9 ? ` 0${date .getDate ()} ` : ` ${date .getDate ()} ` ;
27
+ const strDate = ` ${year }-${month }-${day } ` ;
28
+ return strDate ;
29
+ }
22
30
}
23
31
24
32
export default MyDate ;
You can’t perform that action at this time.
0 commit comments