vue-music(18)取消和确定弹窗蒙层的设置

首先,要写一个弹窗的confirm组件:

<template>
  <transition name="confirm-fade">
    <div class="confirm">
      <div class="confirm-wrapper">
        <div class="confirm-content">
          <p class="text"></p>
          <div class="operate">
            <div class="operate-btn left"></div>
            <div class="operate-btn"></div>
          </div>
        </div>
      </div>
    </div>
  </transition>
</template>

<style lang="stylus" scoped>
  @import "~common/stylus/variable"

  .confirm
    position fixed
    left 0
    right 0
    top 0
    bottom 0
    z-index 999
    background-color: $color-background-d
    &.confirm-fade-enter-active
      animation: confirm-fadein 0.3s
      .confirm-content
        animation: confirm-zoom 0.3s
    .confirm-wrapper
      position: absolute
      top: 50%
      left: 50%
      transform: translate(-50%, -50%)
      z-index: 1000
      .confirm-content
        width: 270px
        border-radius: 13px
        background: $color-highlight-background
        .text
          padding: 19px 15px
          line-height: 22px
          text-align: center
          font-size: $font-size-large
          color: $color-text-l
        .operate
          display: flex
          align-items: center
          text-align: center
          font-size: $font-size-large
          .operate-btn
            flex: 1
            line-height: 22px
            padding: 10px 0
            border-top: 1px solid $color-background-d
            color: $color-text-d
            &.left
              border-right: 1px solid $color-background-d


  @keyframes confirm-fadein // 过渡动画
    0%
    opacity: 0
    100%
    opacity: 1

  @keyframes confirm-zoom
    0%
      transform: scale(0)
    50%
      transform: scale(1.1)
    100%
      transform: scale(1)
</style>

confirm的组件的显示和隐藏需要由自身来控制,所以,要在他里面定义一个data,再定义两个方法供外部使用:

  data () {
    return {
      showFlag: false
    }
  }
  methods: { // 提供外部接口
    show () {
      this.showFlag = true
    },
    hide () {
      this.showFlag = false
    }
  }

confirm接收三个文本的值

props: {
    text: {
      type: String,
      default: '确定删除吗?'
    },
    cancelBtnText: {
      type: String,
      default: '取消'
    },
    confirmBtnText: {
      type: String,
      default: '确认'
    }
  },

给confirm上面的按钮添加点击事件:

<div class="operate-btn left" @click="cancel">{{cancelBtnText}}</div>
      <div class="operate-btn" @click="confirm">{{confirmBtnText}}</div>


cancel () {
      this.hide()
      this.$emit('cancel')
    },
    confirm () {
      this.hide()
      this.$emit('confirm')
    }

然后在父组件里面监听:

<confirm ref="confirm" :text="'是否清空所有'" @confirm="clearSearch"></confirm>

clearSearch () {
      this.clearSearchHistory()
    },

在子组件阻止冒泡事件
在子组件最外层的div上加上@click.stop

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值