Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

VUE三元表达式的结果里面如何使用函数?

<td>{{item.last_login_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}
    <br/>
    {{item.cookie_expired_time > 0 ? (item.cookie_expired_time|timeFormat('yyyy-MM-dd hh:mm:ss')) : '无限期'}}
</td>

如上代码,上面的last_login_time的格式化就是没有问题的,但是下面的会报错:

(found in <Root>)
warn @ vue.js:634
warnNonPresent @ vue.js:2047
has @ vue.js:2092
eval @ VM3573:3
renderList @ vue.js:2637
eval @ VM3573:3
Vue._render @ vue.js:3551
updateComponent @ vue.js:4067
get @ vue.js:4478
Watcher @ vue.js:4467
mountComponent @ vue.js:4074
Vue.$mount @ vue.js:9044
Vue.$mount @ vue.js:11944
Vue._init @ vue.js:5012
Vue @ vue.js:5078
(anonymous) @ manage_user.js?v=1602471424:4
success @ global.js?v=1602471424:106
handleSuccess @ jquery.min.js:142
w.onreadystatechange @ jquery.min.js:141
XMLHttpRequest.send (async)
ajax @ jquery.min.js:141
sendAjax @ global.js?v=1602471424:86
(anonymous) @ manage_user.js?v=1602471424:3
ready @ jquery.min.js:29
u @ jquery.min.js:37
vue.js:634 [Vue warn]: Error in render: "TypeError: timeFormat is not a function"
......

此时如果我把代码改成:

<td>{{item.last_login_time|timeFormat('yyyy-MM-dd hh:mm:ss')}}
    <br/>
    {{item.cookie_expired_time > 0 ? item.cookie_expired_time : '无限期'}}
</td>

就是没有问题的,但是我希望这个时间戳是格式化的,请问该怎么办啊?求大神指点,谢谢。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
{{item.cookie_expired_time > 0 ? $options.filters.timeFormat(item.cookie_expired_time, 'yyyy-MM-dd hh:mm:ss'): '无限期'}}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...