vue.js - 在特定页面上渲染某些东西
问题描述
所以我得到了这个 base.vue 布局,我在这里有我的顶部导航和其余内容,我想知道是否可以在粘性 div 中添加输入类型搜索并仅在特定路线页面上呈现它?例如,我不想在每个页面上都有搜索栏,而只是在我进入用户视图时出现,我可以在其中过滤它们。
.sticky.top-0.h-14.bg-white-200.shadow.px-8.flex.items-center
input(type="search" placeholder="search)
.container.max-w-full.mx-auto.p-8
router-view
解决方案
在您的脚本中添加一个计算属性,检查当前路由路径是否为/users
:
computed:{
isUsersPath(){
return this.$route.path==='/users'
}
}
然后在模板中使用它:
div(v-if="isUsersPath").sticky.top-0.h-14.bg-white-200.shadow.px-8.flex.items-center
input(type="search" placeholder="search)
.container.max-w-full.mx-auto.p-8
router-view
推荐阅读
- php - 在 Slim Framerwork 的容器上设置 $app 实例是一种不好的做法吗?
- r - 我在 R2jags 中看不到模型结果 - 出了什么问题?
- laravel - Laravel 8查找方法结果404未找到
- visual-studio-code - 在 VSC 上,我可以复制/粘贴折叠代码并保持折叠状态吗?
- python - FastApi + Gunicorn workers + Google 应用引擎
- authentication - 如何从服务器端访问 grpc 客户端 ssl 证书信息?
- python - 熊猫按时隙计数
- python - 使用 firebase 用户 UID 作为 id 创建 django 用户
- javascript - 在带有选定叠加层名称的传单地图上添加文本框
- python - 如何为多个分类器聚合 StratifiedKFold 拆分的预测