前端Vue光标在输入框内, 内容清空。光标离开,内容显示。

博客涉及前端领域,包含JavaScript和Java相关信息技术内容,但具体内容未给出。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      <van-form>
        <van-field
            v-model="username"
            maxlength="10"
            :rules="[{ required: true, message: '请输入您的姓名' }]"
            @focus="inputFocus"
            @blur="inputBlur"
          />
          <van-field
            v-model="npcNo"
            maxlength="20"
            :rules="[{ required: true, message: '请输入代表证号' }]"
            @focus="inputFocusnpc"
            @blur="inputBlurnpc"
          />
          <div class="submit-btn" @click="onSubmit">请您登录</div>
        </van-form>

export default {
  data() {
    return {
      username: "您的姓名",
      npcNo: "代表证号",
    };
  },
  methods: {
    onSubmit() {
      this.$refs.loginForm
        .validate()
        .then((res) => {
          this.handleLogin();
        })
        .catch((err) => {});
    },
// 后台接口方法
   handleLogin() {
      let req = {
        name: this.username,
        npcNo: this.npcNo,
      };
      this.$post(loginApi, req)
        .then((res) => {
          if (res.code !== 0) {
            this.$toast.fail(res.msg || "请求失败");
            return;
          }
          setSessionStorage("userInfo", JSON.stringify(res.data));
          this.$router.push({ path: "/hand" });
        })
        .catch((err) => err);
    },
  // 光标在输入框内 姓名清空
    inputFocus() {
      this.username === "您的姓名" && (this.username = "");
    },
    inputBlur() {
      this.username === "" && (this.username = "您的姓名");
    },
    // 光标在输入框内 证号清空
    inputFocusnpc(){
      this.npcNo === "代表证号" && (this.npcNo = "");
    },
    inputBlurnpc(){
      this.npcNo === "" && (this.npcNo = "代表证号");
    }
  },
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值