<!-- 点击筛选从底部弹出 --> <tui-drawer :mode="'bottom'" :visible="bottomDrawer" @close="closeDrawer"> <view class="d-container both"> <view class="drawer-title"> <view></view> <view style="font-weight: bold;">全部筛选</view> <gs-icon-text class="icon" icon="icon-chacha1" color="#535d73" fontSize="1.5em" @click="closeDrawer"></gs-icon-text> </view> <view> <gs-title title="办学性质" fontSize="30rpx"></gs-title> <view class="flex mb20 mt20" style="justify-content: space-between;"> <view class="education">公办</view> <view class="education">民办</view> </view> <gs-title class="mb20" title="等级" fontSize="30rpx"></gs-title> <view class="level" v-for="(item, index) in level" :key="index">{{ item }}</view> <gs-title class="mb35 mt35" title="类别" fontSize="30rpx"></gs-title> <view class="category" v-for="(item, index) in category" :key="index">{{ item }}</view> <view class="designatedMajors flex"> <gs-title class="mb35 mt35" title="单招专业" fontSize="30rpx"></gs-title> <gs-icon-text v-show="appoint != '指定专业'" icon="icon-right" fontSize="12px" color="#b6baca" iconPos="right" @click="designatedMajors">切换专业</gs-icon-text> </view> <view class="appoint" :class="{active:appoint != '指定专业'}" @click="designatedMajors">{{ appoint }}</view> <gs-title class="mb35 mt35" title="双高院校" fontSize="30rpx"></gs-title> <view style="margin-bottom: 150rpx;"> <view class="doubleheight" v-for="(item, index) in doubleheight" :key="index">{{ item.name }} <view>{{ item.level }}</view> </view> </view> </view> </view> <view class="tabbar"> <view class="resetting">重置</view> <view class="complete" @click="closeDrawer">完成</view> </view> </tui-drawer>onLoad((option) => { if (option.name) { bottomDrawer.value = true uni.pageScrollTo({ scrollTop:800 }) appoint.value = option.name } })如何在option.name为true的情况下让筛选滚动至单招专业上去
时间: 2023-08-05 20:02:09 浏览: 183
你可以在 `onLoad` 函数中添加一个条件判断,当 `option.name` 为 true 时,使用 `uni.nextTick` 函数在下一次 DOM 更新之后,调用 `uni.pageScrollTo` 函数将页面滚动至指定位置。具体代码如下:
```javascript
onLoad((option) => {
if (option.name) {
bottomDrawer.value = true
if (appoint.value !== option.name) {
appoint.value = option.name
uni.nextTick(() => {
uni.pageScrollTo({
scrollTop: 800
})
})
}
}
})
```
在上述代码中,使用 `if (appoint.value !== option.name)` 条件判断是为了避免重复调用 `uni.pageScrollTo` 函数,提高性能。
相关问题
<template ref="aaa" #就业> <view class="both"> <view class="mb20 mt20" style="font-weight: bold;font-size: 30rpx;">就业行业分布</view> <view class="frame"> <view class="frame-f">医疗保健</view> <tui-progress :percent="30.46" show-info></tui-progress> <view class="frame-f">医药</view> <tui-progress :percent="24.62" show-info></tui-progress> <view class="frame-f">医疗设备</view> <tui-progress :percent="10.29" show-info></tui-progress> <view class="frame-f">快消</view> <tui-progress :percent="6.19" show-info></tui-progress> <view class="frame-f">其他行业</view> <tui-progress :percent="18.83" show-info></tui-progress> </view> <view class="mb20 mt20" style="font-weight: bold;font-size: 30rpx;">岗位去向</view> <tui-charts-pie ref="aaa" diam="250" type="2" @click="onClick"></tui-charts-pie> <view class="mb20 mt20" style="font-weight: bold;font-size: 30rpx;">地区分布</view> <view class="frame"> <view class="frame-f">北京市</view> <tui-progress :percent="30.46" show-info></tui-progress> <view class="frame-f">华中地区</view> <tui-progress :percent="24.62" show-info></tui-progress> <view class="frame-f">深圳市</view> <tui-progress :percent="10.29" show-info></tui-progress> <view class="frame-f">西南地区</view> <tui-progress :percent="6.19" show-info></tui-progress> <view class="frame-f">广州市</view> <tui-progress :percent="18.83" show-info></tui-progress> </view> </view> </template> </gs-tabs>如何用uniapp的vue3获取上述代码插槽的ref
在uniapp的vue3中,可以通过以下方式获取上述代码插槽的ref:
1. 在模板中给插槽标签添加ref属性,如下所示:
```
<gs-tabs>
<template #就业 ref="mySlot">
<!-- 插槽内容 -->
</template>
</gs-tabs>
```
2. 在组件中通过`$refs`访问插槽的ref,如下所示:
```
<script>
export default {
methods: {
handleGetSlotRef() {
const mySlot = this.$refs.mySlot;
console.log(mySlot); // 打印出插槽的ref
}
}
}
</script>
```
需要注意的是,`$refs`只有在组件渲染完成后才能访问到,因此需要在合适的生命周期函数中或者事件处理函数中访问`$refs`。
<template> <view class="container"> <swiper class="swiper-con both" :indicator-dots="true" :autoplay="true" :interval="2000" :duration="500"> <swiper-item v-for="item in swi" :key="item"> <image class="swiper-imag" :src="item"></image> </swiper-item> </swiper> <tui-tab :tabs="tabs" scroll @change="change" isSticky="true"></tui-tab> </view> </template> <script setup> import { reactive, ref } from 'vue' const tabs = reactive([ '推荐', '食品', '水果蔬菜', '新款男装', '内衣', '女装', '百货', '医药', '手机', '鞋包' ]) const tabBars = reactive([ { name: '凉拌洋葱' }, { name: '南瓜粥' }, { name: '酸辣土豆丝' }, { name: '西红柿炒鸡蛋' }, { name: '酸菜鱼' }, { name: '糖醋排骨' }, { name: '糖醋鱼' }, { name: '鱼香肉丝' }, ]) const change = (index)=>{ index = index } const swi = reactive([ '../../static/images/banner/1.jpg', '../../static/images/banner/2.jpg', '../../static/images/banner/3.jpg', '../../static/images/banner/4.jpg', '../../static/images/banner/5.jpg', ]) </script> <style lang="scss"> .container { ::v-deep .swiper-con { height: 300rpx; .uni-swiper-wrapper { border-radius: 16rpx; } .swiper-i { border-radius: 16rpx; } .swiper-imag { height: 100%; width: 100%; } } } </style>根据tui-tab标签选项卡绑定他对应的内容并且能滑动跟随
您可以将每个标签对应的内容放在一个数组中,然后使用v-for指令循环渲染出来,并将tab的index绑定到swiper的current属性上,实现切换标签时,滑动跟随的效果。具体代码如下:
<template>
<view class="container">
<swiper class="swiper-con both" :indicator-dots="true" :autoplay="true" :interval="2000" :duration="500" :current="currentIndex">
<swiper-item v-for="(item, index) in swi" :key="index">
<image class="swiper-imag" :src="item"></image>
</swiper-item>
</swiper>
<tui-tab :tabs="tabs" scroll @change="change" isSticky="true"></tui-tab>
<view class="tab-content">
<view class="tab-item" v-for="(item, index) in tabBars" :key="index" :class="{'active': currentIndex === index}">
<text>{{item.name}}</text>
</view>
</view>
</view>
</template>
<script setup>
import { reactive, ref } from 'vue'
const tabs = reactive([
'推荐',
'食品',
'水果蔬菜',
'新款男装',
'内衣',
'女装',
'百货',
'医药',
'手机',
'鞋包'
])
const tabBars = reactive([
{ name: '凉拌洋葱' },
{ name: '南瓜粥' },
{ name: '酸辣土豆丝' },
{ name: '西红柿炒鸡蛋' },
{ name: '酸菜鱼' },
{ name: '糖醋排骨' },
{ name: '糖醋鱼' },
{ name: '鱼香肉丝' },
])
const change = (index) => {
currentIndex = index
}
const swi = reactive([
'../../static/images/banner/1.jpg',
'../../static/images/banner/2.jpg',
'../../static/images/banner/3.jpg',
'../../static/images/banner/4.jpg',
'../../static/images/banner/5.jpg',
])
const currentIndex = ref(0)
</script>
<style lang="scss">
.container {
::v-deep .swiper-con {
height: 300rpx;
.uni-swiper-wrapper {
border-radius: 16rpx;
}
.swiper-i {
border-radius: 16rpx;
}
.swiper-imag {
height: 100%;
width: 100%;
}
}
.tab-content {
display: flex;
flex-wrap: wrap;
margin-top: 20rpx;
.tab-item {
width: 25%;
height: 100rpx;
display: flex;
justify-content: center;
align-items: center;
border-top: 2rpx solid #f5f5f5;
border-left: 2rpx solid #f5f5f5;
&:last-child {
border-right: 2rpx solid #f5f5f5;
}
&:nth-child(4n+1) {
border-left: none;
}
&:nth-last-child(-n+4) {
border-bottom: 2rpx solid #f5f5f5;
}
&.active {
background-color: #f5f5f5;
}
}
}
}
</style>
阅读全文