vue代码:
<view class="detail">
<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" collection="notice" loadtime="onready"
action="cnt_add_action" :where="where" getone="true">
<view v-if="error">{{error.message}}</view>
<view v-else-if="data">
<view class="detail-title">
标题:{{data.title}}
</view>
<view class="detail-header">
<view class="detail-header__logo">
<image src="../../../static/logo.png" mode="aspectFill"></image>
</view>
<view class="detail-header__content">
<view class="detail-header__content-info">
<uni-dateformat :date="data.submit_time" />
<text>{{data.browse_count}} 浏览</text>
</view>
</view>
</view>
</view>
</unicloud-db>
</view>
cnt_add_action.js
const db = uniCloud.database();
const dbCmd = db.command
module.exports = {
before: async (state, event) => {
//如何接受参数文章的_id
// let _id=event.command.$db[1].$param[0]._id.operands[0]
// await db.collection('notice').doc(_id).update({
// browse_count:dbCmd.inc(1)
// })
},
after: async (state, event, error, result) => {
if (error) {
throw error
}
return result
}
}
1 个回复
DCloud_uniCloud_WYQ
你应该从state内取出具体读了那个文章(从where方法的参数内获取),参考:https://uniapp.dcloud.net.cn/uniCloud/jql.html#action