English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Below is the code for the Vue custom directive drag functionality, as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Instance Methods</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <script src="../js/vue1.0.js"></script> <script src="../js/vue-resource.js"></script> <script> //Custom Directive Vue.directive('drag',function(){ var oDiv = this.el; oDiv.onmousedown = function(ev){ var disX = ev.clientX -oDiv.offsetLeft; var disY = ev.clientY - oDiv.offsetTop; document.onmousemove = function(ev){ var l = ev.clientX-disX; var t = ev.clientY-disY; oDiv.style.left = l+'px'; oDiv.style.top = t+'px'; }; document.onmouseup = function(){ document.onmousemove=null; document.onmouseup=null; }; }; }); window.onload = function(){ var vm = new Vue({ el:'#box', data:{} }); } </script> </head> <body> <div id="box"> <div v-drag :style="{width:100px', height:100px', background:'aqua', position:'absolute', right:0, top:0}> </div> </div> </body> </html>
Let's take a look at the Vue custom keyboard information
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8> <title>Custom Keyboard Information</title> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <script src="../js/vue1.0.js"></script> <script src="../js/vue-resource.js"></script> <script> Vue.directive('on').keyCodes.ctrl=17; Vue.directive('on').keyCodes.myenter=13; window.onload = function(){ var vm = new Vue({ el:'#box', data:{}, methods:{ show:function(){ alert(111); } } }); } </script> </head> <body> <div id="box"> <input type="text" @keydown.ctrl="show"> <hr> <input type="text" @keydown.myenter="show | debounce 2000"> </div> </body> </html>
The above-mentioned is the Vue custom directive drag functionality and keyboard information introduced by the editor for everyone. Hope it will be helpful to everyone. If you have any questions, please leave a message, and the editor will reply to everyone in time. Here we also thank everyone for their support of the Yelling tutorial website!
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, has not been manually edited, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (Please replace # with @ when sending an email to report, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)