_.each 没用过,所以使用了 jQuery 的方法实现
这里使用sweetalert2!不是sweetalert!
// 加入购物车
$('.btn-add-to-cart').click(function () {
axios.post('{{ route('cart.add') }}', {
'sku_id': $('label.active input[name=skus]').val(),
'amount': $('.cart_amount input').val()
}).then(function(res){
Swal('', '成功加入购物车', 'success');
}).catch(function (err){
if(err.response.status == 401){
Swal('', '请先登录', 'warning');
}else if(err.response.status == 422){
let html = '<div>';
$.each(err.response.data.errors, function(index, value){
html += value[0] + '<br/>';
})
html+='</div>';
Swal({
type: 'error',
title: html,
})
}else{
Swal('', '系统错误,请联系客服', 'warning');
}
})
})
推荐文章: