inputValue(newVal) { this.isClearBtn = newVal ? true : false; if (this.timer) { clearTimeout(this.timer); } if (!this.inputValue) { this.searchData = []; return; } this.timer = setTimeout(() => { const result = []; this.cityList.map(v => { v.list.forEach((item) => { if (/^[a-zA-Z]+$/.test(item.pinyin) && item.pinyin.toLowerCase().includes(this.inputValue.toLowerCase()) || item.name.includes(this.inputValue)) { result.push(item); } }); }) this.searchData = result; if (this.searchData.length === 0) { this.hasNoData = true; } else { this.hasNoData = false; } }, 500); },
时间: 2024-03-03 19:52:16 浏览: 16
这段代码看起来是一个 Vue.js 组件中的 inputValue 方法。当组件中绑定的输入框的值发生变化时,该方法会被调用。首先,它根据输入框的值来判断是否需要显示清除按钮(将 isClearBtn 属性设置为 true 或 false)。然后,它通过一个定时器来实现防抖功能,避免频繁地执行搜索操作。如果输入框的值为空,则会清空搜索结果并返回。否则,它会遍历城市列表,并将符合条件的城市信息加入到一个名为 result 的数组中。符合条件的城市信息指的是城市名称包含输入框的值或城市名称的拼音包含输入框的值(不区分大小写)。最后,它将 result 数组保存到 searchData 属性中,并根据搜索结果的数量来判断是否需要显示“无搜索结果”的提示信息(将 hasNoData 属性设置为 true 或 false)。
相关问题
watch: { item: { handler(newVal, oldVal) { this.model = newVal this.imgPathLxfj = '/xwql/' + this.model.xmbh + '/yglx/lxfj' this.imgPathXcms = '/xwql/' + this.model.xmbh + '/yglx/xcms' this.onlyread = this.model.lxzt != 1 ? false : true } } },
这段代码是一个Vue组件的watch属性,用于监听item属性的变化。当item属性发生变化时,会执行handler函数。
在handler函数中,将newVal赋值给this.model,即将新的item值赋给model属性。然后根据this.model.xmbh拼接出两个图片路径imgPathLxfj和imgPathXcms。这些路径用于展示图片或者上传图片时的接口地址。
最后,根据this.model.lxzt的值判断是否将onlyread属性设置为true或false。如果lxzt不等于1,则将onlyread设置为false,否则设置为true。这个onlyread属性可能用于控制表单字段的只读状态或其他操作。
总体来说,这段代码的作用是监听item属性的变化,并根据新的item值更新相关的数据和状态。
watch(() => [...props.component_infos], (newval:any, oldval) => { // leftimg_lists.value = { // commonComponentList: newval.filter(f => f.panel_class == 'common'), // drawComponentList: newval.filter(f => f.panel_class == 'draw'), // chartComponentList: newval.filter(f => f.panel_class == 'chart') // }; leftimg_lists.value = newval.forEach((item:any)=>{ if(item.child.length){ item.child.forEach((sItem:any)=>{ if(sItem.child.length){ sItem.child.forEach((iItem:any)=>{ iItem.create_type = "draggable" iItem.type= iItem.name iItem.title= iItem.name iItem.props= ['prop_data'] if (iItem.extendAttr) { iItem.extend_attr = JSON.parse(iItem.extendAttr) } }) } }) } }) console.log(newval,'newval'); console.log( leftimg_lists.value ,' leftimg_lists.value '); });
这段代码使用了Vue.js的watch API,当props.component_infos的值发生变化时,会执行回调函数。回调函数首先将props.component_infos转换为数组,然后根据panel_class属性将组件分类,并将结果存储在leftimg_lists.value对象中。
接下来,回调函数使用forEach()方法遍历props.component_infos数组,并对其进行修改。如果组件具有子组件,则将子组件的create_type、type、title和props属性设置为固定值,并从extendAttr属性中解析出extend_attr属性。
最后,回调函数打印出新的props.component_infos值和leftimg_lists.value值,用于调试和验证。
总的来说,这段代码是在Vue.js框架中,用于对props.component_infos属性进行监听,并在其发生变化时进行分类和修改。