1.给soup-item组件跳转到编辑页面传递id参数
const props =defineProps({
item:{
type:Object,
default(){
return{}
}
}
})
const goEdit =()=>{
uni.navigateTo({
url:"/pages_self/soup/edit?id="+props.item._id
})
}
2.在edit页面中引入onload事件来获取id
import {onLoad} from"@dcloudio/uni-app";
let id;
onLoad((e)=>{
id=e.id;
if(id){
getDetail() //如果存在id调用下面的方法
}
})
创建获取数据方法用id
const getDetail =async()=>{
let {result:{errCode,data}}= await db.collection("soup-chicken").where({_id:id}).get({getOne:true}); //where进行定点查询,getone是保证数组只有一个嵌套
if(errCode==0){
formDate.value=data; 然后赋值到数据模型,因为都是v-model双向绑定,所以能直接显示
}
}