【菜狗work前端】小程序加if判断时不及时刷新 vs Web

零、前提:

实现input输入数字不大于10000(需要配合type=number,maxlength=5,这里没写)

一、探究代码:

复制代码
 <input v-model="model1" @input="changeModel1" placeholder="请输入拒收件数"/>

const model1=ref(0)
const changeModel1=()=>{
    console.log('model1',model1.value)
    //是否去掉此处if判断
    if(model1.value>10000){
        console.log('model1>10000')
        model1.value = model1.value.slice(0, 4);
        console.log('model1',model1.value)
    }    
}

ps:vue2也试了一下,跟vue2还是vue3无关

二、探究结果:

1.web端/uniapp转微信小程序-未加if判断-及时更新

2.web端-加了if判断-及时更新

uniapp转微信小程序-加了if判断-未及时更新

三、AI分析原因:

四、解决方案:

解决uniapp转微信小程序-加了if判断-未及时更新:加一个nextTick(()=>{})即可

复制代码
import { ref, nextTick } from 'vue';

const changeModel1=()=>{
    if(model1.value>10000){
        nextTick(() => {
            model1.value = model1.value.slice(0, 4);
        }
    }    
}
相关推荐
曲幽16 小时前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
icebreaker17 小时前
Weapp-vite:原生模式之外,多一种 Vue SFC 选择
前端·vue.js·微信小程序
icebreaker17 小时前
重走 Vue 长征路 Weapp-vite:编译链路与 Wevu 运行时原理拆解
前端·vue.js·微信小程序
曲幽2 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
曲幽3 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
大米饭消灭者4 天前
Taro是怎么实现一码多端的【底层原理】
微信小程序·taro
曲幽4 天前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
FliPPeDround5 天前
Vitest Environment UniApp:让 uni-app E2E 测试变得前所未有的简单
微信小程序·e2e·前端工程化
FliPPeDround5 天前
微信小程序自动化的 AI 新时代:wechat-devtools-mcp 智能方案
微信小程序·ai编程·mcp
码云数智-大飞5 天前
如何创建自己的小程序,码云数智与有赞平台对比
微信小程序