0

I'm working on Laravel and Vuejs, I'm calling API from my vue js usign Axios and getting returned data in a Object. But that Object not giving or getting any data on next method in same vue page.

My first function:

getCompanyPaymentMethodLists: function(){
            let that = this;
            axios.get('/api/payment_method/get_company_payment_method')
                .then((response) => {
                that.company_payment_method_lists = response.data;
                /* Generate sale_paids object */
                if(that.company_payment_method_lists){
                  var cash_payment_method_id = that.company_payment_method_lists.filter(function (payment_method) {
                        return payment_method.name == "Cash";
                  });
                  /* For Cash Payment*/                      
                  that.customer_order_details.cash_payment_method_id = cash_payment_method_id[0].id;
                } 
            })
            .catch(function (error) {
                that.errors = error;
            });
        },

And my Second function: In this function I want get the object property of that.customer_order_details.cash_payment_method_id , but it's giving null

getSalePaidDetail:  function(){
          let that = this;
          console.log('working' + that.customer_order_details.cash_payment_method_id); // Print Null
          axios.post('/api/sale_paids/get_sale_paid_history', {
              sale_id: null,
              cash_payment_method_id: that.customer_order_details.cash_payment_method_id
          })
          .then((sale_paid) => {                 
              that.customer_order_details.sale_paids = sale_paid.data;
          })
          .catch(function (error) {
              that.errors = error;
          });  
        },

Here that.customer_order_details is defined object in:

data(){
        return{ 
              customer_order_details:{                  
              cash_payment_method_id: null,
        }
     }
leaveme_alone
  • 576
  • 2
  • 5
  • 24

1 Answers1

0

Got the solution myself, thanks for your effort.

async mounted() {
        let that = this;               
        await that.getCompanyPaymentMethodLists(); 
        await that.getSalePaidDetail(); 
    },

Then in side:

methods: {  
getCompanyPaymentMethodLists: function(){
            let that = this;
            return axios.get('/api/payment_method/get_company_payment_method')
                .then((response) => {
                that.company_payment_method_lists = response.data;
                /* Generate sale_paids object */
                if(that.company_payment_method_lists){
                  var cash_payment_method_id = that.company_payment_method_lists.filter(function (payment_method) {
                        return payment_method.name == "Cash";
                  });
                  /* For Cash Payment*/                      
                  that.customer_order_details.cash_payment_method_id = cash_payment_method_id[0].id;
                } 
            })
            .catch(function (error) {
                that.errors = error;
            });
        },
getSalePaidDetail:  function(){
          let that = this;
          console.log('Heda working' + that.customer_order_details.cash_payment_method_id);

          axios.post('/api/sale_paids/get_sale_paid_history', {
              sale_id: null,
              cash_payment_method_id: that.customer_order_details.cash_payment_method_id
          })
          .then((sale_paid) => {
              that.customer_order_details.sale_paids = sale_paid.data;
          })
          .catch(function (error) {
              that.errors = error;
          });  
        },

}
leaveme_alone
  • 576
  • 2
  • 5
  • 24