vue编写button组件

export default {
    props:{
        type: {
            type: String,
            default: normal
        },
        value: {
            type: String,
            default: value
        },
    },
    // 直接变成真实dom,免去转义打包的过程
    render(h) {
        return h('button', {
            class: {
                btn: true,
                'btn-success': this.type === 'success',
                'btn-danger': this.type === 'danger',
                'btn-warning': this.type === 'warning',
                'normal': !this.type
            },
            domProps: {
                innerText: this.text || '默认按钮'
            }
        })
    }
}
<style scoped>
    .btn{
        width: 100px;
        height: 40px;
        text-align: center;
        line-height: 40px;
        color: #fff;
    }
    .btn-success{
        background: green;
    }
    .btn-warning{
        background: orange;
    }
    .btn-danger{
        background: red;
    }
    .normal{
        background: blue~~~~;
    }
    
</style>

评论

暂无评论