vue js里如何封装这个函数 :)

新手上路,请多包涵

题目描述

vue js里如何封装这个函数

        
        let heightc = [];
        let heightd = [];
        let isOlc = true;
        let isOld = true;
        
        clickLic(index){
            this.changes('.olc',isOlc,index,heightc)
        },
        clickLid(index){
            this.changes('.old',isOld,index,heightd)
        },
        changes(olc,istrue,index,heights){
            let  ol = document.querySelectorAll(olc);

            if (istrue) {
                for(var i = 0;i<ol.length; i++){
                    ol[i].style.height = 'auto';
                    heights.push(getComputedStyle(ol[i]).height);
                    ol[i].style.height = '0px';
                }
                istrue = false
            }
            
            if (ol[index].style.height == '0px') {
                ol[index].style.height = heights[index]     
            }else{
                ol[index].style.height = 0 
            }
        },

问题是每次点击执行时 istrue 还是 true 并没有变为 false  导致每次执行这个true 并且后面也不会触发 else条件






阅读 2.3k
1 个回答
新手上路,请多包涵

看了下函数参数,布尔值是不能进行修改的。 把 istrue 换成 if (heights == '') {....} 就行了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题