首页 > Web开发 > 详细

vue.js-过滤器 filters使用详细示例

时间:2018-07-12 21:28:11      阅读:144      评论:0      收藏:0      [点我收藏+]

什么也不说了,直接上干货:

   1.首先,获取后台数据到页面,并调用过滤器

在<script>中添加
onRefreshItems (currentPage, perPage) {
if (this.dataUrl) {
this.$http.get(this.dataUrl, {params: {page: currentPage, size: perPage}}).then(res => {
let labels = []
for (var i = 0; i < res.data.length; i++) {
let item = res.data[i]
item.status = report.formatStatus(item.status)
labels.push(item)
}
this.items = labels
})
}
},

2.添加过滤器,在<script>中添加
filters: {
formatStatus (status) {
return report.formatStatus(status)
}
}

3.编写js文件(report.js)
export default {
formatStatus (status) {
if (status === ‘TO_BE_PUT_INTO_STORAGE‘) {
status = ‘未入库‘
} else if (status === ‘PARTIAL_ARRIVAL‘) {
status = ‘月台部分收货‘
} else if (status === ‘WAREHOUSING_COMPLETION‘) {
status = ‘已全部入库‘
} else if (status === ‘‘) {
status = ‘‘
}
return status
}
}
4.引入
import report from ‘@/components/Table/report.js‘

如有错误欢迎留言指点,谢谢

vue.js-过滤器 filters使用详细示例

原文:https://www.cnblogs.com/chenshuquan/p/9301838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!