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
1. Business Scenario I have been doing developmen...
1. Background During the server development proce...
Key Takeaways: 1. Mastering CSS3 3D animation 2. ...
This article describes how to build a MySQL maste...
1. When to execute setUp We all know that vue3 ca...
This article shares the specific code of JavaScri...
SQL statement DROP TRIGGER IF EXISTS sys_menu_edi...
Secondly, the ranking of keywords is also related ...
Preface Today, I was reviewing the creational pat...
Table of contents 1. Introduction to Compose 2. C...
The results are different in Windows and Linux en...
Less is More is a catchphrase for many designers....
Because if there is no forward slash at the end of...
Download the compressed version of MySQL-5.7.11-w...
"What's wrong?" Unless you are accus...