当前位置: 首页 > news >正文

07前端项目----面包屑

面包屑

    • 效果
      • 实现代码
      • 全局事件总线-$bus

效果

在这里插入图片描述

实现代码

  • 上节searchParams中参数categoryName是表示一二三级分类所点击的列表名
<!--bread面包屑-->
<div class="bread"><ul class="fl sui-breadcrumb"><li><a href="#">全部结果</a></li></ul><ul class="fl sui-tag"><!--三级分类的面包屑--><li class="with-x"  v-for='searchParams.categoryName'>{{searchParams.categoryName}}<i @click="removeCategoryName">×</i></li><!-- 搜索框keyword面包屑--><li class="with-x"  v-for='searchParams.keyword'>{{searchParams.keyword}}<i @click="removeKeyword">×</i></li></ul>
</div>

如果searchParams中存在categoryName属性则展示;
x则是删除该项categoryName事件

methods:{removeCategoryName(){//则将三级列表的categoryName,以及id全部置为undefinedthis.searchParams.categoryName = undefined;this.searchParams.category1Id = undefined;this.searchParams.category2Id = undefined;this.searchParams.category3Id = undefined;//整理参数this.getDate();//地址栏也需要修改,将quey(三级联动)参数移除,但是params参数(搜索框)需要保留(需要判断是否有params参数)//可以省掉if?this.$route.params永远为true,即使没有参数也会返回空对象{}//可以再次跳转/* if(this.$route.params){this.$route.replace({name:'search',params:this.$route.params});*/this.$route.replace({name:'search',params:this.$route.params});}},}

keyword的面包屑:

removeKeyword(){this.searchParams.keyword = undefined;this.getDate();//搜索框置空//路由跳转this.$route.replace(name:'search',query:this.$route.query);}

需要让兄弟组件Header组件的输入框置空
设计组件通信方式:
props:父传子
自定义事件:子传父
vuex:数据状态统一管理
插槽:父传子
pubsub-js:订阅发布
$bus全局事件总线

全局事件总线-$bus

//main.js...省略其他
new Vue({//全局事件总线$bus配置beforeCreate(){Vue.prototype.$bus = this}
})
removeKeyword(){//全局事件绑定this.$bus.$emit('clear');	}
//header组件index.vue
mounted(){this.$bus.$on("clear",()=>{this.keyword = "";})
}
  • 完整代码
removeKeyword(){this.searchParams.keyword = undefined;this.getDate();//搜索框置空//全局事件绑定this.$bus.$emit('clear');	//路由跳转this.$route.replace(name:'search',query:this.$route.query);}

相关文章:

  • JVM有什么调优参数?
  • Java秒杀功能-案例
  • 丝杆升降机蜗轮蜗杆加工工艺深度解析:从选材到制造的全流程技术要点​
  • 软件工程中的维护类型
  • 模型的RAG
  • 运营商二要素认证API接口有哪些发展前景?
  • 基于超启发鲸鱼优化算法的混合神经网络多输入单输出回归预测模型 HHWOA-CNN-LSTM-Attention
  • 【项目日记(三)】
  • pytest-项目结构
  • 明心见性与真如三昧
  • 为什么RPN经过的候选框处理后,要使用rcnn来进行候选框的分类和回归操作?
  • Android audio_policy_configuration.xml加载流程
  • 基于SIMMECHANICS的单自由度磁悬浮隔振器PID控制系统simulink建模与仿真
  • VLAN间通讯技术
  • 关于QTableWidget控件中不显示Item的问题解决方法
  • MCP是什么?
  • windows搭建wireshark抓包snmp协议环境步骤
  • 3.THREE.FogExp2 全面详解 + 实例演示 + 深度解析
  • 【Redis】SpringDataRedis
  • 【单片机 C语言】单片机学习过程中常见C库函数(学习笔记)
  • 视频丨英伟达总裁黄仁勋:美勿幻想AI领域速胜中国
  • 微软上财季净利增长18%:云业务增速环比提高,业绩指引高于预期
  • 上海:以税务支持鼓励探索更多的创新,助力企业出海
  • 司法服务保障西部陆海新通道建设,最高法专门发文
  • 海口市政协党组成员、秘书长、机关党组书记汪娟被查
  • 锦江酒店:第一季度营业收入约29.42亿元,境内酒店出租率同比增长