I try like this :
const actions = {
    getData ({ commit }, payload) {
      const params = {}
      if(payload) {
        if (payload.dateFrom) { params.date_from = payload.dateFrom }
        if (payload.dateTo) { params.date_to = payload.dateTo}
      }
      axios
        .get(`${api}/reports/list`, {params})
        .then(r => r.data)
        .then(res => {
          console.log(res)
        })
    }
}
If I console.log(payload), the result like this :
{from: '2022-07-01', to: '2022-07-30'}
payload is optional
My code is working. But I want to know if there is a more concise way to express it.
 
     
     
     
    