vue3.0+element plus 的el-container中,el-aside可以拖拽的方法(drag)


首先在setup中定義一個類

 const widthData=reactive({
      with:500
    });

然后編寫方法:

    const updateWidth=()=>{
        
           let resize= document.getElementById("asideId");
           console.log(resize);
resize.onmousedown = function(e) {
        // resize.style.background = "#818181";
        let startX = e.clientX;
        // resize.left = resize.offsetLeft;
        document.onmousemove = function(e) {
        
          let endX = e.clientX;
          let moveLen = endX - startX;
          startX = endX;
           widthData.with += moveLen;
        };
        document.onmouseup = function() {
          // 顏色恢復
          resize.style.background = "";
          document.onmousemove = null;
          document.onmouseup = null;
        };
        return false;
      };

      }

然后在onMounted中調用方法

最后在el-aside中加入id="asideId"  :width="widthData.with+'px'" 綁定即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM