1. 程式人生 > >vue.js-過濾器 filters使用詳細示例

vue.js-過濾器 filters使用詳細示例

sta orm == refresh rri using 詳細 length ram

什麽也不說了,直接上幹貨:

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使用詳細示例