今天写东西碰到一些问题,现在要记录下来

<div class="account">
      帐号:<input
        type="text"
        placeholder="请输入您的账号"
        v-model="account"
      /><span>*</span
      ><span id="tishiAccount" :style="tishiAccount_style">{{ msg }}</span>
    </div>

实现功能是:改变span的字体颜色

使用dom和ref都无法实现,更换了另一种方法-----直接改变样式

 data() {
    return {
 

      tishiAccount_style: {
        color: "",
      },
    };
  },
 methods: {
  
    checkAccount() {
      let reg = /^\w{6,15}$/;
      if (reg.test(this.account)) {
        this.msg = "账户名正确√";
        this.tishiAccount_style.color = "green !important";
      } else {
        this.msg = "账户名错误×";
        this.tishiAccount_style.color = "red !important";
      }
    },
    check() {
      this.checkAccount();
    },
  },

 

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐