Vue는 개발자가 최신 반응형 웹 애플리케이션을 빠르게 구축할 수 있는 인기 있는 JavaScript 프레임워크입니다. 매우 흥미로운 기능 중 하나는 매우 인기 있고 실용적인 기능인 사이드바 드래그입니다. 이 기사에서는 Vue를 사용하여 사이드바 드래그를 구현하는 방법을 소개합니다.
먼저 Vue.js를 설치해야 합니다. npm 또는 Yarn을 사용하여 설치하고 Vue.js를 프로젝트에 도입할 수 있습니다.
<script></script>
Vue.js에서는 구성 요소를 정의하고 사이드바 드래그를 위한 코드를 작성할 수 있습니다. 구성 요소에서. 이 예에서는 DragSidebar라는 구성 요소를 만듭니다. DragSidebar 구성 요소에서는 드래그와 mouseX라는 두 가지 데이터 속성을 정의해야 합니다. dragging은 사이드바가 드래그되고 있는지 여부를 나타내고 mouseX는 마우스의 X 좌표를 나타냅니다.
<template> <div> <div> <div> <slot></slot> </div> </div> </div> </template> <script> export default { data() { return { dragging: false, mouseX: 0, sidebarX: 0 } }, computed: { translate() { return `translate3d(${this.sidebarX}px, 0, 0)` } }, methods: { mousedown(event) { this.dragging = true this.mouseX = event.clientX }, mouseup() { this.dragging = false }, mousemove(event) { if (this.dragging) { const diff = event.clientX - this.mouseX this.sidebarX += diff this.mouseX = event.clientX } } } } </script> <style> .drag-container { display: flex; align-items: stretch; height: 100vh; overflow: hidden; } .sidebar { width: 320px; min-width: 320px; height: 100%; background-color: #F2F2F2; transition: transform .3s ease; } .content { padding: 24px; } </style>
위 코드에서는 마우스 누르기, 놓기 및 이동 이벤트를 각각 처리하는 mousedown, mouseup 및 mousemove의 세 가지 메서드를 정의했습니다. mousedown에서 드래그 속성을 true로 설정했습니다. 이는 사이드바가 드래그되기 시작하고 마우스의 X 좌표가 기록된다는 의미입니다. mouseup에서는 드래그 속성을 false로 설정했습니다. 이는 사이드바 드래그가 중지됨을 의미합니다. mousemove에서는 마우스가 이동한 거리에 따라 사이드바의 위치를 조정합니다.
마지막으로 상위 구성 요소에서 DragSidebar 구성 요소를 사용하고 그 안에 일부 하위 구성 요소를 추가하여 테스트합니다. 프로젝트 요구 사항에 맞게 일부 CSS 스타일을 직접 추가해야 할 수도 있습니다.
<template> <div> <drag-sidebar> <h1 id="Title">Title</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <p>Suspendisse consectetur pharetra ante sit amet bibendum.</p> </drag-sidebar> <div> <h1 id="Main-content">Main content</h1> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p> <p>Suspendisse consectetur pharetra ante sit amet bibendum.</p> </div> </div> </template> <script> import DragSidebar from './components/DragSidebar.vue' export default { components: { DragSidebar } } </script> <style> .app { height: 100vh; display: flex; } .main { flex-grow: 1; padding: 24px; } </style>
Vue를 사용하여 사이드바 드래그를 구현하는 방법입니다. 위의 단계를 통해 실용적인 사이드바 드래그를 빠르게 구현할 수 있습니다.
위 내용은 예제에서는 vue를 사용하여 사이드바 드래그 기능을 구현하는 방법을 설명합니다.의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

usestate () isareacthookusedtomanagestatefunctionalcomponents.1) itinitializesandupdatesstate, 2) workaledtthetThetThepleFcomponents, 3) canleadto'Stalestate'ifnotusedCorrecrally 및 4) performancanoptimizedUsecandusecaldates.

Reactispopularduetoitscomponent 기반 아카데입, 가상, Richcosystem 및 declarativenature.1) 구성 요소 기반 ectureallowsforeusableuipieces, Modularityandmainability 개선 가능성.

TodebugreactApplicationseffective, UsetheseStradegies : 1) 주소 propdrillingwithContapiorredux.2) handleaSnchronousOperationswithUsestAndUseefect, abortControllerTopReceConditions.3) 최적화 formanceSeMoAnduseCalbackTooid

usestate () inreactAllowsStateManagementInfunctionalComponents.1) itsimplifiessTatemanagement, 2) usethepRevCountFunctionToupDatesTestateSpreviousValue, PropeingStaleScallanceBackferperperperperperperperperperperperperpertoptiMizatio

chelectionSimple, IndependentStateVaribles; useUserEducer () useuserEducer () forcomplexStateLogicor () whenStatedSonpreviousState.1) usestate () isidealforsimpleupdatesliketogglingabooleorupdatingacounter.2) usbetterformanagingmentiplesub-vvalusorac

Usestate는 클래스 구성 요소 및 기타 상태 관리 솔루션보다 우수합니다. 국가 관리를 단순화하고 코드를 더 명확하게하고 읽기 쉽고 React의 선언적 특성과 일치하기 때문입니다. 1) Usestate는 함수 구성 요소에서 상태 변수를 직접 선포 할 수있게합니다. 2) 후크 메커니즘을 통해 다시 렌더링하는 동안 상태를 기억합니다.

useUsestate () forlocalcomponentStateManagement; 고려 사항 forglobalstate, complexlogic, orperformanceissues.1) usestate () isidealforsimple, localstate.2) useglobalstatesolutionslikereduxorcontextforsharedstate.3) optforredooxtoolkitormobxcomcoccomcoccomcoccomcoccomcoccomcoccomcoccomcoccomporccomcoccomporccomcoccomport

reusablecomponentsinreacececodemainabenabilityandefficiency는 hallowingesamecomponentacrossdifferentpartsofanapplicationorprojects.1) 그들을 retuduceredundancyandsimplifyupdates.2) theyseconsistencyinuserexperience.3) theyquireoptim


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

Dreamweaver Mac版
시각적 웹 개발 도구

VSCode Windows 64비트 다운로드
Microsoft에서 출시한 강력한 무료 IDE 편집기

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.

드림위버 CS6
시각적 웹 개발 도구
