欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

uni-app,Vue 使用 filter 过滤或者替换 v-for 的值

程序员文章站 2022-03-06 12:33:57
...

今天做一个 列表循环的时候,有一个值是 unix 的时间,所以需要格式化 时间

就去找了下资料,可以通过 filter 来替换值

直接代码吧,代码简写了,只有重要部分

<template>

<view class="" v-for="(item,index) in jokes" :key="index">
<view class="margin-top">
<uni-card :title="item.title" :note="item.unixtime|dateFormat"><!-- 值的后面 加上过滤器 -->
<text selectable="true" @click="copyData" :data-con="item.content">{{item.content}}</text>
</uni-card>
</view>
</view>
</template>

<script>
export default{
data(){
return {
jokes:[]
}
},
//定义过滤器
filters:{
dateFormat(value){
return utils.timeTodate(‘Y-m-d H:i’,value*1000)
}
}
}
</script>