Vue.js 实现日期格式化:显示中文日期和星期
The code above is for a Vue.js application that displays the current date and day of the week. The code includes a filter that formats the date object to display the year, month, date, and day of the week in Chinese characters. The filter is applied to the date object in the data section of the Vue instance. The formatted date is then displayed in the span element within the div with the ID 'box'.
<div id="box">
<span>{{__(1)_ | nowdate}}</span>
</div>
<script type="text/javascript">
Vue.filter('__(2)___',function(value){
var year=value.getFullYear();
var month=value.getMonth()+1;
var date=value.getDate();
var __(3)_=value.getDay();
var week=‘’;
• switch (day){
case 1:
week="星期一";
break;
case 2:
week="星期二";
break;
case 3:
week="星期三";
break;
case 4:
week="星期四";
break;
case 5:
week="星期五";
break
case 6:
week="星期六";
break
default:
week="星期日";
break;
}
return year +"年" +month+"月"+date+"日"+week;
});
new Vue({
el:"#box",
data:{
date:new Date()
}
})
</script>
</body>
This code demonstrates how to use a Vue.js filter to format a date object into a user-friendly string in Chinese. The filter takes the date object as input and returns a string containing the year, month, date, and day of the week in Chinese characters.
原文地址: https://www.cveoy.top/t/topic/nPfY 著作权归作者所有。请勿转载和采集!