Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'vant' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
(res) => {
console.log(res)
// alert(JSON.stringify(res))
if (res.err_msg == "get_brand_wcpay_request:ok") {
Toast(this.$t('wxpay.succ_toast'))
this.$router.push('/wxpay/done')
} else if (res.err_msg == "get_brand_wcpay_request:fail"){
Toast(this.$t('wxpay.error_toast', {msg: res.err_msg}))
}
this.loading = false
}
);
error => {
console.log('err' + error) // for debug
Toast.fail({
message: error.message,
duration: 1.5 * 1000
})
return Promise.reject(error)
}
)
response => {
const res = response.data
if (res.errno === 501) {
Toast.fail('请登录');
setTimeout(() => {
window.location = '#/login/'
}, 1500)
return Promise.reject('error')
} else if (res.errno === 502) {
Toast.fail('网站内部错误,请联系网站维护人员')
return Promise.reject('error')
} if (res.errno === 401) {
Toast.fail('参数不对');
return Promise.reject('error')
} if (res.errno === 402) {
Toast.fail('参数值不对');
return Promise.reject('error')
} else if (res.errno !== 0) {
// 非5xx的错误属于业务错误,留给具体页面处理
return Promise.reject(response)
} else {
return response
}
}, error => {
console.log('err' + error)// for debug
const res = response.data
if (res.errno === 501) {
Toast.fail('请登录');
setTimeout(() => {
window.location = '#/login/'
}, 1500)
return Promise.reject('error')
} else if (res.errno === 502) {
Toast.fail('网站内部错误,请联系网站维护人员')
return Promise.reject('error')
} if (res.errno === 401) {
Toast.fail('参数不对');
return Promise.reject('error')
} if (res.errno === 402) {
Toast.fail('参数值不对');
return Promise.reject('error')
} else if (res.errno !== 0) {
// 非5xx的错误属于业务错误,留给具体页面处理
return Promise.reject(response)
} else {
return response
}
}, error => {
console.log('err' + error)// for debug
pingpp.createPayment(data.invokeResponse, function(result, err) {
if (result === 'success') {
Dialog.alert({
title: '系统提示',
message: '支付成功',
beforeClose: function (action, done) {
// 关闭弹窗
done();
// 跳转到我的优惠劵
that.$router.push(decodeURI(that.returnUrl));
}
});
} else {
// console.log(err.msg);
// console.log(err.extra);
Dialog.alert({
title: '系统提示',
message: '支付失败:' + err.msg,
});
}, error => {
console.log('err' + error)// for debug
Dialog.alert({
title: '警告',
message: '登录连接超时'
});
return Promise.reject(error)
})
}, error => {
console.log('err' + error)// for debug
Dialog.alert({
title: '警告',
message: '登录连接超时'
});
return Promise.reject(error)
})
let method = 'post';
let path = Url.registerApi;
let params = {
userName: this.userName,
passWord: this.passWord
};
try {
this.loading = true; // 开启按钮注册状态
let res = await registerUser(path, method, params);
console.log(res)
// 将 token & 用户名存储到 localStorage 中
localStorage.setItem('token', res.token);
localStorage.setItem('userName', res.userName);
// 注册成功提示
Toast.success({
duration: 1000,
message: res.message
});
// 1.5 秒后跳转到首页
let timer = setTimeout(() => {
this.$router.push({ name: 'Home' }); // 注册成功跳转到首页
clearTimeout(timer); // 清除定时器
}, 1500);
} catch (error) {
console.log(error)
this.$toast.fail('注册失败');
} finally {
this.loading = false;
}
}
}
}
]
};
},
data() {
return {
menuList: [],
categoryList: [],
categoryContent: [],
pageNum: 0,
type: ""
};
},
mixins: [dataMixin],
components: {
[NavBar.name]: NavBar,
[Tab.name]: Tab,
[Tabs.name]: Tabs,
[Toast.name]: Toast,
[Icon.name]: Icon
},
computed: {},
mounted() {
this.getMenuList();
// this.getCategoryList();
},
methods: {
async getMenuList() {
let res = await apiGetCategoryMenu();
this.menuList = res.data.data.slice(1);
console.log("menuList: ", this.menuList);
var that = this;
var lists = this.carts;
var cartIds = [];
var left = [];
for (var i = 0; i < lists.length; i++) {
if (lists[i].isCheck) {
cartIds.push(lists[i].id);
} else {
left.push(lists[i]);
}
}
cartIds = cartIds.join();
if (cartIds == "") {
Toast("请选择要删除的购物车物品");
} else {
Dialog.confirm({
title: "提示",
message: "确认删除?"
})
.then(() => {
// on confirm
post("shop/api/delCart", {
ids: cartIds,
PHPSESSID: window.localStorage.getItem("PHPSESSID")
}).then(res => {
that.carts = left;
});
let delLen = cartIds.split(",").length;
let num = that.$store.state.cartShopNum;
let lastCartNum = num - delLen;
that.$store.commit("getCartShopNum", {
num: lastCartNum