扫码支付秒杀是一种结合了扫码支付技术和秒杀活动的电子商务促销方式。以下是对该问题的详细解答:
扫码支付:
秒杀活动:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>扫码支付秒杀</title>
<script src="https://cdn.jsdelivr.net/npm/vue@next"></script>
</head>
<body>
<div id="app">
<h1>限时秒杀活动</h1>
<p>商品名称:{{ product.name }}</p>
<p>原价:{{ product.originalPrice }}元</p>
<p>秒杀价:{{ product.seckillPrice }}元</p>
<button @click="handleSeckill" :disabled="isSoldOut || isProcessing">立即抢购</button>
<p v-if="isSoldOut">已售罄</p>
<p v-if="isProcessing">正在处理中...</p>
</div>
<script>
const app = Vue.createApp({
data() {
return {
product: {
name: '热门商品',
originalPrice: 100,
seckillPrice: 10,
stock: 100
},
isSoldOut: false,
isProcessing: false
};
},
methods: {
async handleSeckill() {
if (this.isSoldOut || this.isProcessing) return;
this.isProcessing = true;
try {
// 调用后端API进行秒杀操作
const response = await fetch('/api/seckill', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ productId: this.product.id })
});
const result = await response.json();
if (result.success) {
alert('秒杀成功!');
} else {
this.isSoldOut = true;
alert('秒杀失败,商品已售罄。');
}
} catch (error) {
console.error('秒杀请求失败:', error);
alert('秒杀请求失败,请稍后再试。');
} finally {
this.isProcessing = false;
}
}
}
});
app.mount('#app');
</script>
</body>
</html>
希望以上内容能全面解答您关于扫码支付秒杀的相关疑问!
领取专属 10元无门槛券
手把手带您无忧上云