actions.js 560 Bytes
export default {
  async postProductFav({commit}, {productId, favorite, productType}) {
    let postUrl, params;

    if (productType === 1) {
      postUrl = favorite ? '/api/favorite/add' : '/api/favorite/cancel';
      params = {
        type: 'product',
        fav_id: productId
      };
    } else if (productType === 2) { // ufo
      postUrl = favorite ? '/api/ufo/user/favoriteAdd' : '/api/ufo/user/favoriteCancel';
      params = {
        productId
      };
    }

    const result = await this.$api.get(postUrl, params);

    return result;
  }
};