KFormItem is implemented, it is very simple to use the slot

FormItem:

<template>
    <div class="app">
        <p>KFormItem</p>
        <slot></slot>
        <p v-if="error">{
   
   {error}}</p>
    </div>
</template>


<script>
import {Type} from "@/constants/common.js"
export default {
    data(){
        return {
            error:'',
            value:"ddd"
        }
    },
    methods:{
        // 校验的操
        check(value){
            console.log("." + value)
        }
    },
    mounted(){
        this.$on("input",function(value){
            console.log("..." + value)
            this.value = value;
        });

        this.$on("check",this.check);
    }    
    
}
</script>

<style >

</style>

use:

Since the slot is used, the monitoring event must be added to the mounted life cycle method!

Also modify kInput.vue 

 

The point is that $on and $emit must have the same subject object so that the event can be received!

 

Slots are used in this section!

 

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_15009739/article/details/113799508