VUE customizes how a component inputNumber, like other UI frameworks, does not need to be written on the parent page to change the value.

for example, element-ui
has a component InputNumber
element-ui whose InputNumber component address is as follows: http://element-cn.eleme.io/-sharp/...

.

<template>
  <el-input-number v-model="num3"></el-input-number>
</template>
<script>
  export default {
    data() {
      return {
        num3: 5
      }
    }
  };
</script>

like the InputNumber of element-ui above
you only need to bind v-model to change the value without the need for additional add and minus methods

and the components I wrote are as follows

<template>
    <div class="input-number">
        <span @click="minus" class="btn"></span>
        <span>{{value}}</span>
        <span @click="add" class="btn"></span>
    </div>
</template>
<script>
    export default {
        name: "input-number",
        props: {
              value:{
                  type: Number,
                default: 0
              },
        },
        methods: {
            add(){
                this.$emit("add")
            },
            minus(){
                this.$emit("minus")
            }
        },
    }
</script>

if I write this, I need to write

on the page.
<template>
    <div class="">
        <input-number :value="value" @add="add" @minus="minus"></input-number>
        <input-number :value="value1" @add="add1" @minus="minus1"></input-number>
    </div>
</template>

<script>
    import inputNumber from "@/components/inputNumber"
    export default {
        components: {
            inputNumber
        },
        data() {
            return {
                value:0,
                value1:0,
            }
        },
        methods: {
            add(){
                this.valuePP;
            },
            minus(){
                this.value--;
            },
            add1(){
                this.value1PP;
            },
            minus1(){
                this.value1--;
            },
        }

    }
</script>

like the above, you need to write additional add and minus methods.
use $emit to trigger add and minus methods within the parent component to modify parameters
and then bind to child components to implement
. If a page has multiple components, doesn"t it feel particularly cumbersome for each component to bind two methods

?

the question now is how can I write something like element-ui.
only needs to bind a v-model to change the value directly. There is no need to write anything else.
how to write?
do not understand very well, if possible, please tell me in more detail, thank you!

Jul.01,2022

you have to put the added and subtractive functions in the component. Then each change is done through this.$emit ('input') .

element-ui InputNumber component you can also go to github to see the source code to learn.


I wonder if this is what you want
clipboard.png

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e7df89-99a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e7df89-99a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?