Home  >  Article  >  Web Front-end  >  Vue text box displays the current number of words that can be entered

Vue text box displays the current number of words that can be entered

青灯夜游
青灯夜游forward
2020-07-28 17:27:082285browse

Vue text box displays the current number of words that can be entered

Upload the code directly.

<template>
  <p class="wrapper">
    <p class="parents">
      <textarea placeholder="请输入您要填写的个性签名" maxlength="30" autofocus="true" v-model="val"></textarea>
      <span class="tips">
        可输入
        <b :class="{&#39;remnant&#39;:remnant.length!=0,&#39;zero&#39;:remnant.length==0}">{{remnant}}</b>个字。
      </span>
    </p>
  </p>
</template>

<script>
export default {
  data() {
    return {
      val: "",
      maxLength: 30
    };
  },
  computed: {
    remnant() {
      return this.maxLength - this.val.length;
    }
  }
};
</script>

<style scoped>
.wrapper {
  border-top: 1px solid #999;
  padding: 30px;
}
.parents {
  width: 100%;
  height: 80px;
  position: relative;
}
textarea {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}
.tips {
  position: absolute;
  bottom: 0;
  right: 0;
}
.remnant {
    color: aqua;
}
.zero{
    color: #e81844;
}
</style>

Effect:

Vue text box displays the current number of words that can be entered

Vue text box displays the current number of words that can be entered

Vue text box displays the current number of words that can be entered

A two-way binding and a calculated property Easy to do.

The above is the detailed content of Vue text box displays the current number of words that can be entered. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete