vue中filter的應用場景詳解
filter一般用于過濾某些值,比如我這個字段是空,可是我想在前端顯示“–”,就可以使用到它了。
最近碰到一個需求就是要給某些字段可以設(shè)置權(quán)限去以其他形式顯示,比如以“***”顯示需要隱藏的金額。
1.獲取金額權(quán)限
2.通過filter過濾滿足條件的字段
3.返回隱藏的樣式
看代碼:
//其他的看,看我標注的就可以了
//scope.row 獲取當前行
<template slot-scope="scope">
<template v-if="item.formType == 'label'">
<el-button
v-if="item.link!=undefined"
type="text" size="small" @click="handleColumnClick(item.link,scope.row)">
//filter一般不用的過濾用|
//showLabelValue就不寫出來了
//方法一個參數(shù)對應的filter是兩個參數(shù)
//第一個是前一列返回的值
//第N-1個是你想傳的值
{{ scope.row | showLabelValue(item) | canViewAmount(canViewAmount,xtType,item) }}
</el-button>
<template v-else>
{{ scope.row | showLabelValue(item) | canViewAmount(canViewAmount,xtType,item) }}
</template>
</template>
</template>
export default {
filters: {
//row就是scope.row返回的數(shù)據(jù)
showLabelValue(row,item){
return 'value'
}
//value值, canView權(quán)限, xtType哪個頁面, item列表數(shù)據(jù)
//如果showLabelValue返回的是value,對應的canViewAmount參數(shù)的value就是‘value'
canViewAmount(value, canView, xtType, item) {
//滿足條件用“***”顯示(只是顯示),保存到數(shù)據(jù)庫還是原列表的內(nèi)容
if (!canView && xtType == 'salesOrder') {
if (item.field == 'priceNoTax' || item.field == 'amountNoTax' || item.field == 'price' || item.field == 'amount') {
return '***'
}
}
if (!canView && xtType == 'project') {
if (item.field == 'amount' || item.field == 'amountNoTax') {
return '***'
}
}
return value
}
},
總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注腳本之家的更多內(nèi)容!
相關(guān)文章
Vue+Echarts實現(xiàn)繪制多設(shè)備狀態(tài)甘特圖
這篇文章主要為大家詳細介紹了Vue如何結(jié)合Echarts實現(xiàn)繪制多設(shè)備狀態(tài)甘特圖,文中的示例代碼講解詳細,有需要的小伙伴可以跟隨小編一起學習一下2024-03-03
Antd-vue Table組件添加Click事件,實現(xiàn)點擊某行數(shù)據(jù)教程
這篇文章主要介紹了Antd-vue Table組件添加Click事件,實現(xiàn)點擊某行數(shù)據(jù)教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-11-11
@click.native和@click的區(qū)別及說明
這篇文章主要介紹了@click.native和@click的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08

