当你看到这篇文章的时候,恭喜你,你也遇到了这个问题,首先这个问题是微信小程序的一个问题,在我发布这篇文章的时候还没有解决,但是遇到这个问题,又不能说不兼容iOS,所以只能看看怎么解决他啦
直接上代码:
<template>
<view class="word">
<textarea
v-model="state.key_words"
class="textarea"
placeholder-style="font-size: 28rpx; color: #999"
placeholder="请输入需要生成的文字内容,1-5个字最佳"
/>
</view>
</template>
<script setup>
import { reactive, watch } from 'vue';
const state = reactive({
key_words: "",
})
watch(() => state.key_words, (newVal) => {
const value = newVal.trim();
if(value.length > 5) {
setTimeout(() => {
state.key_words = value.substring(0, 5);
}, 0)
}
}, { deep: true })
<script>
这个方案就是通过监听值的变化来截取字符串,就可以解决这个问题啦