平時封裝組件都是以.vue單文件的方式去弄的。想問一下能不能用Vue.directive 這種方式。試過了網上很多的方法,在全局和局部都試了,貌似沒有效果如:我在某個文件下這樣寫的。代碼的作用是實現可拖拽。這不是重點。這是鏈接http://www.jb51.net/article/1...<template><input v-drag placeholder="您的手機號碼"/></template><script> import Vue from 'vue' Vue.directive('drag', inserted:function(el){ let oDiv=el; oDiv.onmousedown=function(e){ let l=e.clientX-oDiv.offsetLeft; let t=e.clientY-oDiv.offsetTop; document.onmousemove=function(e){ oDiv.style.left=e.clientX-l+'px'; oDiv.style.top=e.clientY-t+'px'; }; oDiv.onmouseup=function(){ document.onmousemove=null; oDiv.onmouseup=null; } }})</script>用時我也在main.js里面試了也沒有效果。很少提問題,望各位幫個忙最好給一個小小的demo不需要對上面的代碼進行解釋
【急】vue2.0 單文件的模式,怎么使用Vue.directive
MMTTMM
2019-02-28 11:04:51