我正在研究 Laravel 和 Vuejs,我正在从我的 vue js usign Axios 调用 API,并在对象中获取返回的数据。但是该对象没有在同一 vue 页面中的下一个方法上提供或获取任何数据。
我的第一个功能:
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;
});
},
我的第二个函数:在这个函数中,我想获取 that.customer_order_details.cash_payment_method_id 的对象属性,但它给出了 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;
});
},
这里 that.customer_order_details 是在以下位置定义的对象:
data(){
return{
customer_order_details:{
cash_payment_method_id: null,
}
}