vue组件之支付弹框

//照搬的时候注意在vuex里面定义  this.$store.commit("progectile");控制组件显示隐藏的 同时在父组件的子组件标签上也加上v-show="this.$store.state.progectile"判断一下
<template>
    <div class="progectile">
       <span class="del" @click="hidden"></span>
       <span class="password">密码</span>
       <input ref="pwd" type="tel" maxlength="6" v-model="msg" class="pwd" unselectable="on" />
        <ul class="pwd-wrap" @click="focus">
            <li :class="msg.length == 0?'psd-blink':''"><i v-if="msg.length > 0"></i></li>
            <li :class="msg.length == 1?'psd-blink':''"><i v-if="msg.length > 1"></i></li>
            <li :class="msg.length == 2?'psd-blink':''"><i v-if="msg.length > 2"></i></li>
            <li :class="msg.length == 3?'psd-blink':''"><i v-if="msg.length > 3"></i></li>
            <li :class="msg.length == 4?'psd-blink':''"><i v-if="msg.length > 4"></i></li>
            <li :class="msg.length == 5?'psd-blink':''"><i v-if="msg.length > 5"></i></li>
        </ul>
       <!-- <input type="password" class="inputpra" onkeyup="value=value.replace(/[^(\d)]/g,'')" maxlength="6" v-model="pass" :class="pass.length=='6'?'active':''"/> -->
       <span class="confirm" @click="refer">确认</span>
    </div>
</template>

<script>
export default {
  data() {
    return {
      msg: ""
    };
  },
  props:{
      ask:String
  },
  watch: {
    msg(curVal) {
      if (/[^\d]/g.test(curVal)) {
        this.msg = this.msg.replace(/[^\d]/g, "");
      }
    }
  },
  methods: {
    hidden() {
    //控制支付弹框显示隐藏的变量
      this.$store.commit("progectile");
      this.msg = "";
    },
    focus() {
      this.$refs.pwd.focus();
    },
    async refer() {
      if (!this.msg) {
        this.$toasted.error("请输入完善信息", { icon: "error" }).goAway(2000);
        return;
      }
      try {
        // await等待一个异步返回的结果 如果没有await 会报user is undefined 获取不到
        let { id, num } = this.$store.state.buydetosit;
        let res = await this.http.post(this.ask, {
          security: this.msg,
          id: id,
          num: num
        });
        if (res.code == 200) {
          this.$toasted.success(res.message).goAway(1500);
          this.$store.commit("progectile");
          this.msg = "";
        } else {
          this.$toasted.error(res.message, { icon: "error" }).goAway(2000);
          this.$store.commit("progectile");
          this.msg = "";
        }
      } catch (error) {
        this.$toasted.error(error.message, { icon: "error" }).goAway(2000);
        this.$store.commit("progectile");
        this.msg = "";
      }
    }
  },
  created() {
    this.$store.commit("progectilefalse");
  }
};
</script>

<style scoped>
.progectile {
  width: 90%;
  height: 3.5rem;
  position: fixed;
  top: 4rem;
  bottom: 4rem;
  left: 5%;
  z-index: 9;
  display: flex;
  flex-direction: column;
  box-shadow: 1px 1px 5px #888888;
  background: #ffffff;
}
.progectile .del {
  width: 0.5rem;
  height: 0.5rem;
  background: url("../../../public/image/close.png") no-repeat;
  background-size: 0.5rem 0.5rem;
  margin-left: 92%;
}
.progectile .password {
  font-size: 0.4rem;
  margin: 0 auto;
}
.progectile .inputpra {
  width: 5.5rem;
  height: .8rem;
  background: url("../../../public/image/weibiaoti1.png") no-repeat;
  background-size: 100% 0.8rem;
  padding-left: .4rem;
  padding-right: -.4rem;
  letter-spacing: 0.67rem;
  font-size: 0.5rem;
  overflow: hidden;
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%,-38%);
  color: black;
  text-shadow: 0 0 0 black;
}
.progectile .inputpra.active {
  color: transparent;
}
.progectile .confirm {
  width: 100%;
  text-align: center;
  height: 1rem;
  line-height: 1rem;
  font-size: 0.4rem;
  color: #5136d9;
  border-top: 1px solid #5136d9;
  margin-top: 24%;
}
input {
  width: 0.1px;
  height: 0.1px;
  color: transparent;
  position: relative;
  top: .23rem;
  background: #000000;
  left: .46rem;
  border: none;
  font-size: 18px;
  opacity: 0;
  z-index: -1;
}

.psd-blink {
  display: inline-block;
}
.pwd-wrap {
  width: 90%;
  height: 1rem;
  padding-bottom: 1px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid #ddd;
  display: flex;
   justify-content: space-between;
  cursor: pointer;
  position: absolute;
  left: 0;
  right: 0;
  top: 32%;
  z-index: 0;
}
li {
 list-style:none;
  text-align: center;
  line-height: 1rem;
  -webkit-box-flex: 1;
  width: 15%;
  border-right: 1px solid #ddd;
  background: #888888;
}
i {
  height: .2rem;
  width: .2rem;
  border-radius: 50%;
  background: #000;
  display: inline-block;
}
</style>

Vue3中,父组件可以通过使用`ref`属性给子组件添加一个引用,并在父组件的方法中调用子组件的方法。 首先,在父组件模板中,可以使用`ref`属性给子组件添加一个引用。比如: ```html <template> <child ref="childComponent"></child> </template> ``` 接下来,在父组件的方法中,可以通过`this.$refs`来获取子组件的引用,并调用子组件的方法。比如: ```javascript export default { methods: { callChildMethod() { this.$refs.childComponent.childMethod(); } } } ``` 最后,在子组件中,需要定义`childMethod()`方法,供父组件调用。比如: ```javascript export default { methods: { childMethod() { console.log('child method is called'); // 在这里可以实现弹框的逻辑 } } } ``` 这样,当父组件的`callChildMethod()`方法被调用时,它将通过子组件的引用调用子组件的`childMethod()`方法,从而实现了父组件调用弹框中子组件方法的功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [vue 父页面调用子页面的方法(非常有用)](https://blog.csdn.net/chengchong_cc/article/details/131229724)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值