简单的vue按钮组件

发布时间:2019-05-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了简单的vue按钮组件脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

点击确定之后更改状态
button.vue

<template>
    <div class="container">
        <button
        v-if='state'
        @click='confirm'
        class='confirm'
        :style="{background:btnColor}"
        >
            <slot>按钮</slot>
        </button>
        <button class="confirm" :disabled='!state' v-else>正在加载</button>
    </div>
</template>

<script>
export default{
    data(){
        return {
            state:true,
            btnColor:'red'
        }
    },
    props:{
        text:{
            type:String,
            default:'注册'
        }
    },
    methods:{
        confirm(){
            this.state=false;
            this.btnColor = 'blue';
            this.$emit("confirm");
        },
        cancel(){
            let that=this;
            setTimeout(function(){
                  that.state = true;
                  that.btnColor = 'red';
            }, 1000)
        }
    }
}
</script>
<style scoped>
.confirm {
  border: none;
  color: #fff;
  width: 100%;
  padding: 1rem 0;
  border-radius: 4px;
  font-size: 1.6rem;
  background: #5da1fd;
}
</style>

index.vue

<template>
    <Btn @confirm="confirm" ref="btn">确定</Btn>
</template>

<script>
import Btn from './components/button'
export default {
  components: {
    Btn
  },
  methods: {
    confirm(){
        this.$refs.btn.cancel()
    }
  }
}
</script>

脚本宝典总结

以上是脚本宝典为你收集整理的简单的vue按钮组件全部内容,希望文章能够帮你解决简单的vue按钮组件所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。