为了账号安全,请及时绑定邮箱和手机立即绑定

vue自定义指令,报错.可以在线运行的小demo

vue自定义指令,报错.可以在线运行的小demo

花开花落_青藤 2017-06-28 15:41:56
<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="X-UA-Compatible" content="ie=edge"><title>自定义指令--拖拽</title></head><body><div id="app"><div v-drag :style="{background:'red', width:'200px',height:'200px',position:'absolute',left:0,top:0}"></div></div></body><script src="https://unpkg.com/vue/dist/vue.js"></script><script>var vm= new Vue({el:'#app',data:{}})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.onmouseup=function(){document.onmousemove=null;document.onmouseup=null;}}}})</script></html>
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1879 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信