【二】鸡汤来咯开发学习笔记-34

前端 · 2024-07-28

1.更改表数据默认提交为审核中(0),list获取数据数据库中filed中加入status

2.手动修改云数据库里面以前的数据(把审核通过改几个为审核中和审核未通过),方便开发,审核状态功能

3.在common.js中建立公共审核状态组,方便调用

export const statList =[
    {
        "value": 0,
        "text": "审核中"
    },
    {
        "value": 1,
        "text": "审核通过"
    },
    {
        "value":2,
        "text":"审核不通过"
    }
]

建立一个根据value值返回状态对象的方法(运用到回调函数)

//传入value值返回状态对象
export function stateFormat(value){
    return statList.find(item=>item.value==value)  js的回调箭头函数item=>item.value==value,这个就是如果后面相等,就返回item否则为空
}

4.然后再soup-item中引入stateFormat,并用v-if和v-else进行判断展示

        <view class="group" v-if="item.status==1">
            <view class="every">
                <uni-icons type="heart" color="#a7a7a7" size="16"></uni-icons>
                <text class="font" v-if="item.like_count">{{item.like_count}}</text>
            </view>
            <view class="every">
                <uni-icons type="star" color="#a7a7a7" size="16"></uni-icons>
                <text class="font" v-if="item.collect_count">{{item.collect_count}}</text>
            </view>
            <view class="every">
                <uni-icons type="chatbubble" color="#a7a7a7" size="16"></uni-icons>
                <text class="font" v-if="item.comment_count">{{item.comment_count}}</text>
            </view>
        </view>
        <view v-else>
            {{stateFormat(item.status).text}}
        </view>
    </view>
Theme Jasmine by Kent Liao