【菜狗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);
        }
    }    
}
相关推荐
爱隐身的官人10 小时前
ctfshow-web213
web·sqlmap·ctfshow
汤姆yu13 小时前
基于微信小程序的个性化漫画阅读推荐系统
微信小程序·小程序
pixle019 小时前
从零学习Node.js框架Koa 【一】 Koa 初探从环境搭建到第一个应用程序
前端·node.js·web·koa.js·web全栈·node服务端框架
Le1Yu20 小时前
微信小程序端服务器接口:全部服务以及实战
微信小程序·小程序
蒋星熠20 小时前
爬虫中Cookies模拟浏览器登录技术详解
开发语言·爬虫·python·正则表达式·自动化·php·web
合作小小程序员小小店1 天前
web网页开发,在线%台球俱乐部管理%系统,基于Idea,html,css,jQuery,jsp,java,ssm,mysql。
java·前端·jdk·intellij-idea·jquery·web
dcloud_jibinbin2 天前
【uniapp】解决小程序分包下的json文件编译后生成到主包的问题
前端·性能优化·微信小程序·uni-app·vue·json
fthux2 天前
孩子的名字有救了
微信小程序·typescript·ai编程
Best2 天前
uniapp 微信小程序记录
微信小程序·小程序·uni-app
亮子AI3 天前
【小程序】详细比较微信小程序的 onLoad 和 onShow
微信小程序·小程序