简介:
在app开发收尾阶段,需要对之前通过localforage的方式获取记录的方式进行修改。目前后端采用node.js完成。
收藏功能前后端对接:
1、后端提供的接口
collections/insert //添加
collections/select //查询所有
collections/select //根据ID查询
collections/delete //根据ID删除
collections/getIsCollection //判断是否已经被收藏
 
2、前端接口参数结构
以添加为例
export function addCollection(data) {
  return request({
    method: "post",
    url: "collections/insert",
    noloading: true,
    localParams: {
      apiName: MARS_COLLECTIONS_POINT,
      type: "put"
    },
    data
  })
}
 
3、实现方法
 const lineData = {
    title: adressName, //名称
    type: "line", //收藏的类型,点就是 point 线就是 line
    info: JSON.stringify({  //收藏的数据
      line: line
    })
  }
let currentID: string // 当前的ID
// 后台添加数据
const addCollectionLine = async () => {
  const { status, data } = await api.addCollection(lineData )
  if (status === 200) {
    $message({
      message: "已收藏",
      type: "success"
    })
    icon.value = "ant-design:star-filled"
    currentID = data.data.id
  }










