您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍“vue的filter如何应用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“vue的filter如何应用”文章能帮助大家解决问题。
filter一般用于过滤某些值,比如我这个字段是空,可是我想在前端显示“–”,就可以使用到它了。
最近碰到一个需求就是要给某些字段可以设置权限去以其他形式显示,比如以“***”显示需要隐藏的金额。
1.获取金额权限
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就不写出来了
//方法一个参数对应的filter是两个参数
//第一个是前一列返回的值
//第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返回的数据
showLabelValue(row,item){
return 'value'
}
//value值, canView权限, xtType哪个页面, item列表数据
//如果showLabelValue返回的是value,对应的canViewAmount参数的value就是‘value'
canViewAmount(value, canView, xtType, item) {
//满足条件用“***”显示(只是显示),保存到数据库还是原列表的内容
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
}
},关于“vue的filter如何应用”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。