Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report