工作随记work

技术相关

联系我们

联系人:祁海涛

手 机:13212709526

邮 箱:527845769@qq.com

网 址:ddwl.site

地 址:湖北省武汉市青山区白玉山街道

nuxt中输入框输入展示下拉防抖

时间:2024-09-02 15:24 阅读:23 来源:互联网

模板部分

<input type="text" name="s" value="" placeholder=" "

                                                    class="ui-autocomplete-input" @input="getresult()" v-model="s" @click.stop>

js部分

getresult(){

            if (this.s && this.s.length>2){

                let that = this

                if(that.timer) clearTimeout(that.timer)

                // 设立新的定时器

                that.timer = setTimeout(function () {

                    // console.log(that.s)

                    if (that.stimer != that.s){

                        that.$axios.post("/site/product/index",{search_text:that.s})

                        .then((res)=>{

                            // console.log(res)

                            if (res.status == 200) {

                                that.resultlist = res.data.list.data

                                that.resultshow=true

                            }

                        })

                        // console.log(that.stimer,that.s)

                        that.stimer = that.s

                    }


                }, 1000)//delay










                // let s = this.s

                // this.tool.debounce(

                // // console.log("333"),1000)

                // function(s){

                //     console.log("111")

                // }

                // ,1000)




                // this.$axios.post("/site/product/index",{search_text:this.s})

                // .then((res)=>{

                //     // console.log(res)

                //     if (res.status == 200) {

                //         this.resultlist = res.data.list.data

                //         this.resultshow=true

                //     }

                // })

            }else{

                this.resultshow=false

            }


        },


Copyright © 2023  东东网络工作室 版权所有  备案号:鄂ICP备2020021332号-1 网站地图