美文网首页
Weex button 高亮自定义

Weex button 高亮自定义

作者: fordG | 来源:发表于2019-07-11 16:35 被阅读0次
image.png
image.png

控件代码

<template>
    <div>
        <div :style="buttonStyleCopy" class="button" @touchstart="startTouch" @touchend="endTouch">
            <text :style="textStyleCopy">{{ text }}</text>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        //接受反馈, 是否向外传递点击事件信号 外界命名属性要和这个字段一模一样
        disable: {type: Boolean, default: false},
        text: { type: String, default: 'button' },
        //点击时背景色
        touchColor: { type: String, default: 'blue' },
        //点击时文字颜色
        touchTextColor: {type: String, default: 'white'},
        buttonStyle: {
            default: {
                backgroundColor: '#F6F6F6',
                width: 750,
                height: 100
            }
        },

        textStyle: {
            default:{
                color: '#000000'
            }
        }
    },
    data() {
        return {
            buttonStyleCopy: {},
            textStyleCopy: {}
        };
    },
    components: {},
    computed: {
    },
    created() {
        this.buttonStyleCopy = this.copyObject(this.buttonStyle)
        this.textStyleCopy = this.copyObject(this.textStyle)
    },
    methods: {
        copyObject(obj) {
            return JSON.parse(JSON.stringify(obj));
        },

        startTouch(e) {
            console.log(this.buttonStyleCopy.backgroundColor, this.touchColor)
            this.buttonStyleCopy.backgroundColor = this.touchColor;
            this.textStyleCopy.color = this.touchTextColor
            this.$forceUpdate()
            //传递点击事件
            if(!this.disable){
                this.$emit('update:disable', true)
                this.$emit('tap', {})
            }
        },
        endTouch(e) {
            this.buttonStyleCopy.backgroundColor = this.buttonStyle.backgroundColor;
            this.textStyleCopy.color = this.textStyle.color
            this.$forceUpdate()
            console.log(this.buttonStyleCopy.backgroundColor, this.touchColor)
        }
    }
};
</script>

<style scoped>
.button {
    justify-content: center;
    align-items: center;
}
</style>

示例代码

<template>
    <root :statue="true">
        <select-button @tap="tap" :disable.sync="disable"></select-button>
        <select-button 
            @tap="tap" 
            :disable.sync="disable"
            :buttonStyle="{
                width: 200,
                height: 150,
                backgroundColor: 'red'
            }"
            >
        </select-button>
    </root>
</template>

<script>
    import Root from '../../../components/root-view/index.vue'
    import SelectButton from './selectButton.vue'
    export default {
        data() {
            return {
                disable: false,
            };
        },
        components: {
            Root,
            SelectButton
        },
        computed: {},
        created() {},
        methods: {
            tap(){
                console.log('tap')
                let self = this
                setTimeout(e=>{
                    self.disable = false
                }, 3000)
            }
        }
}
</script>

<style scoped>
</style>

相关文章

  • Weex button 高亮自定义

    控件代码 示例代码

  • QQ粘性布局

    按钮button自定义button设置圆角半径cornerRadius取消高亮状态重写setHighlighted...

  • UIButton 疑难杂症

    button 不能正常显示高亮,轻点 button 时不高亮,而长按时才高亮搜索发现,问题在于将 button 加...

  • UIButton应用细节

    1、消除UIButton的高亮状态:1)自定义button2)重写Highlighted的set方法 2、修改bu...

  • iOS开发总结

    1、禁止手机睡眠 2、隐藏某行cell 3、禁用button高亮 button.adjustsImageWhenH...

  • ios开发小技巧-取消button点击高亮效果

    为button设置图片,默认会有点击闪烁的效果(即高亮效果),为取消button点击高亮的效果可以使用一下方法: ...

  • Weex富文本WXRichLabel实践

    在上篇的基础上处理: Weex自定义WXRichText组件实践Weex 富文本 Weex协议 Weex链接 WX...

  • button去高亮

    有时候按住button不放的时候,会有灰黑色的高亮效果,如果不想要这个效果,可以用以下两个方法去掉。 (1), ...

  • iOS bug 记录

    1、自定义UIButton,自定义button中添加UIImageView和UILabel。设置button的en...

  • iOS的一些小技巧

    技巧1: 如何禁用UIButton的高亮效果方法1: button.adjustsImageWhenHighl...

网友评论

      本文标题:Weex button 高亮自定义

      本文链接:https://www.haomeiwen.com/subject/tamdkctx.html