【问题标题】:Axios - how can I conditionally append fieldsAxios - 我如何有条件地附加字段
【发布时间】:2018-01-02 00:52:49
【问题描述】:

我有这个 Axios 补丁,但如果 hyperlink_column 不为空,我只想包含最后三个补丁。我该怎么做?

谢谢,

米克

  axios.patch('/' + self.table + '/' + self.rowId,{

                name: self.name,
                SQL:self.SQL,
                area_id:self.area_id,
                report_type_id:self.report_type_id,
                mode:self.mode,
                database_connection_id:self.database_connection_id,
                pagination: self.pagination,
                show_export_buttons : self.show_export_buttons,
                filters : self.filters,
                description : self.description,
                category_id : self.category_id,

                hyperlink_column : self.hyperlink_column,
                linked_report : self.linked_report,
                link_parameter : self.link_parameter,

【问题讨论】:

    标签: javascript ajax vue.js axios


    【解决方案1】:

    因为从外观上看,第二个参数看起来像是一个对象,所以一种方法是调用一个函数作为第二个参数,并将您的数据作为参数传递到 self 中。然后该函数将检查self.hyperlink_column 是否存在,然后相应地返回一个对象。像这样

    Repl

    PS : 这是使用闭包完成的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-28
      • 1970-01-01
      • 2017-11-14
      • 1970-01-01
      相关资源
      最近更新 更多