首页 > Vue,is not a function,date转换YYYY-MM => YYYY年MM月---初学者

Vue,is not a function,date转换YYYY-MM => YYYY年MM月---初学者

edu.start_time 格式是 例:2016-09

<div class="module-bd" v-for="edu in education">
    <p>入学时间:{{setDate(edu.start_time , "年月日")}}</p>
</div>
setDate(date,format){
    let result={year:0,month:0,day:0};//当然这里可以默认1970-1-1日
    if(date){
        format.replace(/y+|Y+|M+|d+|D+/g,function(m,a,b,c){//这里只做了年月日  加时分秒也是可以的
            date.substring(a).replace(/\d+/,function(d){c=parseInt(d,10)});
            if(/y+/i.test(m)&&!result.year)result.year=c;
            if(/M+/.test(m)&&!result.month)result.month=c;
            if(/d+/i.test(m)&&!result.day)result.day=c;
        });
    }
    let todayDate  =  result.year + "年" + result.month + "月"
    return todayDate;
},

1.为什么会报错?
2.Vue有什么更好的YYYY-MM 转换成 YYYY年MM月的方法么?

提示我


看得出你想转换下日期为中文,setDate是个方法。不过你通过{{}}想展示在页面一定是Vue实例中的data。建议你使用computed来计算。

关于日期有个库非常好用,推荐monent.js


Vue有一个功能叫filter,请参照帮助文档自定义filter

http://cn.vuejs.org/guide/cus...

【热门文章】
【热门文章】