码迷,mamicode.com
首页 > 移动开发 > 详细

uni-app中实现左侧导航栏效果

时间:2019-06-10 18:33:29      阅读:3082      评论:0      收藏:0      [点我收藏+]

标签:oba   global   选项   scrollto   methods   scrolltop   span   spec   script   

HTML:

 1  <view class="list">
 2       <!-- 一级 -->
 3       <scroll-view class="list-left" scroll-y :style="‘height:‘+height+‘px‘">
 4             <view v-if="dataList.length>0" class="list-nav" @click="categoryClickMain(item.id,index)" :key="item.id" :class="index==categoryActive?‘active‘:‘‘" 
 5              v-for="(item,index) in dataList">
 6               {{item.deptName}}
 7             </view>
 8       </scroll-view>
 9       <!-- 二级 -->
10       <scroll-view class="list-right" scroll-y :scroll-top="scrollTop" @scroll="scroll" :style="‘height:‘+height+‘px‘" scroll-with-animation>
11           <view class="right-nav" @tap="openOrder">
12               {{rightView.deptName}}
13           </view>
14       </scroll-view>
15  </view>

JavaScript:

<script>
    export default {
        data() {
            return {
                dataList: [],
                subList: [],
                height: 0,
                categoryActive: 0,
                scrollTop: 0,
                scrollHeight: 0,
                subs:[],
                rightView:{},
                isShow:true,
                img_url:this.$GLOBAL.BASE_IMG,
                "departmentLevel": 1,
                "gbDepartmentName": "",
                deptName:‘‘,
                isActive: 0 //默认激活的选项卡
            };
        },
        onLoad() {
            this.dataload();
            this.height = uni.getSystemInfoSync().windowHeight;
        },
         methods: {
            categoryClickMain(id,index) {
                this.categoryActive = index;
                let current = this.dataList.find(item => item.id === id);
                
                if(current) {
                    this.rightView = current.subs[0]
                }
            },
             dataload() { //获取基础数据
                 this.getInspectData(); 
             },
             getInspectData(options) {
                 let data = {
                      "args": {
                        "areaCode": 10001,
                        "orgCode": 1,
                        "systemCode": 1
                      },
                      "token": "string"
                 }
                 this.$request({
                     url: ‘url‘,
                     data: data,
                     success: (res) => {
                        console.log(‘data===‘,res.data.result)
                        let dataList = [];
                        this.dataList = res.data.result; //一级
                        this.rightView = res.data.result[0].subs[0] //二级
                     },
                 },‘selDepartment‘)
             },
            openOrder() {
                uni.navigateTo({
                    url:‘../order/order‘
                });
            }
          }

 效果如下:

技术图片

点击左边的,右侧显示对应的内容

uni-app中实现左侧导航栏效果

标签:oba   global   选项   scrollto   methods   scrolltop   span   spec   script   

原文地址:https://www.cnblogs.com/renxiao1218/p/10999365.html

(0)
(1)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!