图例
第一步:给图标按钮绑定事件 @click='handleClear'
<!-- 搜索历史标题 --> <div class="history"> <h4>搜索历史</h4> <icon @click='handleClear' type='clear' size='16'/> </div> <!-- 搜索历史关键字列表 --> <div class="history-list"> <div :key='index' v-for='(item, index) in hkw' class="history-item"> <navigator :url="'/pages/search_list/main?kw=' + item"> {{item}} </navigator> </div>第二步:处理事件
methods: { handleClear () { // 清除历史关键字:清除本地缓存;清除data中的数据 // history-命名应该与缓存的名字一致 wx.removeStorageSync('history') this.hkw = [] }, }