验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

vue遮罩和ref的使用方法是什么

阅读:734 来源:乙速云 作者:代码code

vue遮罩和ref的使用方法是什么

1、创建conform.vue,其内容如下:



import { onMounted, ref,  } from 'vue'
export default {
  name: 'conform',
  props:{
    title: {
      type: String,
      default: '温馨提示'
    },
    text: {
      type: String,
      default: ''
    },
  },
  setup(){
    const fade = ref(false)
    const open = () => {
      fade.value = true
    }
// 取消
    const cancel = () => {
      fade.value = false
    }
// 确认
    const submit = () => {
      fade.value = false
    }
    return { fade, open, cancel, submit}
  }
}


.xtx-confirm {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  z-index: 8888;
  background: rgba(0,0,0,0);
  &.fade {
    transition: all 0.4s;
    background: rgba(0,0,0,.5);
  }
  .wrapper {
    width: 400px;
    background: #fff;
    border-radius: 4px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-60%);
    opacity: 0;
    &.fade {
      transition: all 0.4s;
      transform: translate(-50%,-50%);
      opacity: 1;
    }
    .header,.footer {
      height: 50px;
      line-height: 50px;
      padding: 0 20px;
    }
    .body {
      padding: 20px 40px;
      font-size: 16px;
      .icon-warning {
        color: red;
        margin-right: 3px;
        font-size: 16px;
      }
    }
    .footer {
      text-align: right;
      cursor: pointer;
      .cancel{
        margin-right: 20px;
        cursor: pointer;
      }
      .submit{
        cursor: pointer;
      }
    }
    .header {
      position: relative;
      h4 {
        font-weight: normal;
        font-size: 18px;
      }
      a {
        position: absolute;
        right: 15px;
        top: 15px;
        font-size: 20px;
        width: 20px;
        height: 20px;
        line-height: 20px;
        text-align: center;
        color: #999;
        &:hover {
          color: #666;
        }
      }
    }
  }
}

2、App.vue中的内容如下:





import conform from "@/components/conform.vue";
import {ref} from "vue";
export default {
  name: 'App',
  components:{ conform},
  setup(){
    const conform_ref = ref(null)
    const show_open = ()=>{
      conform_ref.value.open()
    }
    // 特别要注意这种方式,虽然conform_ref没在
    // template中使用但是一定要返回,否则会出问题
    return{conform_ref, show_open}
  }
}
























效果如下:

vue遮罩和ref的使用方法是什么

特别需要注意的是方式一这种方式,虽然conform_ref没在 template中使用但是一定要返回,否则会出问题

分享到:
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
相关文章
{{ v.title }}
{{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
你可能感兴趣
推荐阅读 更多>