在输入框 按下回车后,保存关键字,并放入本地存储

input绑定的confirm事件

<input v-model="keyword" @confirm="saveKeyword" @input="keywordSearch" placeholder="请输入关键字" />

在data中声明的数据

data(){
    return {
       keyword:'',
       historyKeyword: wx.getStorageSync('hkw') || []
    }
}

在methods中声明的事件函数

saveKeyword(){
    // 回车,确认查找
    this.historyKeyword = this.historyKeyword.unshift(this.keyword)
    // 添加到本地缓存
    wx.setStorageSync('hkw', this.historyKeyword)
}
Logo

前往低代码交流专区

更多推荐