index.vue 956 Bytes
Newer Older
dragondean@qq.com's avatar
dragondean@qq.com committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
<template>
    <el-input v-model="valueSync" :type="type" :clearable="clearable" :placeholder="placeholder" />
</template>
<script>
export default {
    data(){
        return {
            valueSync: null
        }
    },
    props:{
        type: String,
        value: [String, Number],
        clearable: Boolean,
        placeholder: String,
        default: String, // 默认值
    },
    computed:{
        
    },
    watch:{
        valueSync(val){
            this.$emit('input', val)
        },
        value(value){
            this.valueSync = value
            this.setDefault()
        }
    },
    created(){
        this.valueSync = this.value
        this.setDefault()
    },
    methods:{
        setDefault(){
            if(!this.default){
                return false
            }
            if(this.valueSync == null || this.valueSync == ''){
                this.valueSync = this.default
            }
        }
    }
}
</script>