1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <template>
- <div class="m-textarea-default">
- <textarea
- :class="styleClass"
- :cols="cols"
- :rows="rows"
- :placeholder="placeholder"
- :value="modelValue"
- :disabled="disabled"
- :maxlength="maxlength"
- :showWordLimit="showWordLimit"
- :readonly="readonly"
- @input="input"
- @focus="focus"
- @blur="blur">
- </textarea>
- <div class="max-length-box" v-if="maxLengthBoxFlag">{{`${n}/${maxlength}`}}</div>
- </div>
- </template>
- <script>
- export default {
- name: "mTextarea"
- };
- </script>
- <script setup>
- import { ref,computed } from 'vue-demi'
- const emit = defineEmits(['update:modelValue','input','focus','blur'])
- const props = defineProps({
- modelValue: {
- type: String,
- default: ''
- },
- placeholder: {
- type: String,
- default: '请输入'
- },
- rows:{
- type:Number,
- default:4
- },
- cols:{
- type:Number,
- default:50
- },
- disabled: {
- type: Boolean,
- default: false
- },
- maxlength: Number,
- showWordLimit: {
- type: Boolean,
- default: false,
- },
- readonly: {
- type: Boolean,
- default: false
- }
- })
- const n = ref(props.modelValue.length || 0)
- const styleClass = computed(() => {
- return {
- 'm-textarea-disabled': props.disabled,
- }
- })
- const maxLengthBoxFlag = computed(() => {
- return props.maxlength != undefined && props.maxlength > 0 && props.showWordLimit
- })
- const input = (e)=>{
- n.value = e.target.value.length
- if(n.value >= props.maxlength){
- n.value = props.maxlength
- }
- emit('update:modelValue',e.target.value)
- emit('input',e.target.value)
- }
- const focus = (e)=>{
- emit('focus',e)
- }
- const blur = (e)=>{
- emit('blur',e)
- }
- </script>
- <style lang="scss" scoped>
- @import '../../styles/components/textarea.scss';
- </style>
|