Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the component of controlling the quantity of goods in Vue

Shulou Source: shulou.com Published: 2022-06-03 10:48:11 10月02日 Update

This article mainly introduces Vue how to control the quantity of goods components, the article introduces in great detail, has a certain reference value, interested friends must read it!

To achieve the effect

Control the quantity of goods package Numbox

-+ 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 based on third-party methods const num = useVModel (props 'modelValue', emit) / / controls the change operation of commodity data const toggle = (n) = > {if (n)

< 0) { // 减一操作 if (num.value >

1) {num.value-= 1}} else {/ / add one operation if (num.value

< 10) { num.value += 1 } } } return { num, toggle } }}.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;}

Used in the parent component

Quantity setup () {/ / quantity of goods / / default value is 1 const num=ref (1) return {num}} above is all the contents of the article "how to control the quantity components of goods by Vue". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Goods quantity control components content data articles values interests two-way guys partners effects methods more knowledge third parties industries information channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux Docker OPPO Reno macOS