The encapsulation and use of Vue's control product quantity component is for your reference. The specific contents are as follows To achieve the effect Control the number of products component package Numbox <template> <div class="xtx-numbox"> <div class="label"> <slot /> </div> <div class="numbox"> <a href="javascript:;" @click='toggle(-1)'>-</a> <input type="text" readonly :value="num"> <a href="javascript:;" @click='toggle(1)'>+</a> </div> </div> </template> <script> import { useVModel } from '@vueuse/core' export default { name: 'XtxNumbox', props: { modelValue: { type: Number, default: 1 }, inventory: type: Number, required: true } }, setup (props, { emit }) { // Bidirectional binding of data controlled by a third-party method const num = useVModel(props, 'modelValue', emit) // Control the change operation of product data const toggle = (n) => { if (n < 0) { // Subtract one operation if (num.value > 1) { num.value -= 1 } } else { // Add one operation if (num.value < 10) { num.value += 1 } } } return { num, toggle } } } </script> <style scoped lang="less"> .xtx-numbox { display: flex; align-items: center; .label { width: 60px; color: #999; padding-left: 10px; } .numbox { width: 120px; height: 30px; border: 1px solid #e4e4e4; display: flex; > a { width: 29px; line-height: 28px; text-align: center; background: #f8f8f8; font-size: 16px; color: #666; &:first-of-type { border-right: 1px solid #e4e4e4; } &:last-of-type { border-left: 1px solid #e4e4e4; } } > input { width: 60px; padding: 0 5px; text-align: center; color: #666; } } } </style> Use in parent component <Numbox v-model='num' >Quantity</XtxNumbox> setup(){ //The number of products//The default value is 1 const num = ref(1) return { num } } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Differences between MySQL MyISAM and InnoDB
>>: Docker builds cluster MongoDB implementation steps
Table of contents 1. Introduction to SQL Injectio...
1. VMware download and install Link: https://www....
<html> <head> <meta http-equiv=&quo...
Programs in Docker containers often need to acces...
Table of contents 1. Animated Christmas Tree Made...
The detailed process of configuring the MySQL dat...
1. Remove MySQL a. sudo apt-get autoremove --purg...
I will use three days to complete the static page...
Main library binlog: # at 2420 #170809 17:16:20 s...
exhibit design Password strength analysis The pas...
In our life, work and study, social networks have ...
Preface Recently, I have been helping clients con...
Open the scheduled task editor. Cent uses vim to ...
Sending emails using PHP's mail function The ...
Preface This article mainly introduces the use an...