Home > Web Front-end > JS Tutorial > 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

青灯夜游
Release: 2020-07-28 17:27:21
forward
2335 people have browsed it

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>
Copy after login

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!

Related labels:
vue
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template