您好,登錄后才能下訂單哦!
這篇文章主要介紹“vue2.0運(yùn)用原生js怎么實現(xiàn)拖拽元素功能”,在日常操作中,相信很多人在vue2.0運(yùn)用原生js怎么實現(xiàn)拖拽元素功能問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”vue2.0運(yùn)用原生js怎么實現(xiàn)拖拽元素功能”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
示例如下:
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/> <meta charset="utf-8"> <title></title> <meta name="keywords" content="" /> <meta name="description" content="" /> <style> .select-item { background-color: #5bc0de; display: inline-block; text-align: center; border-radius: 3px; margin-right: 10px; cursor:pointer; padding: 6px 20px; color: #fff; } .cursored{ cursor: default; } .project-content,.people-content { margin: 30px 50px; } .people-content { margin-top: 30px; } .drag-div { border: 1px solid #5bc0de; padding:10px; margin-bottom: 10px; width: 800px; cursor: pointer; } .select-project-item { display: inline-block; text-align: center; border-radius: 3px; } .drag-people-label{ margin-bottom:0; padding-right:10px; } [v-cloak]{ display:none; } </style> </head> <body> <div class='drag-content' id="dragCon" > <div class='project-content'> <div class='select-item' draggable='true' @dragstart='drag($event)' v-for="pjdt in projectdatas">{{pjdt.name}}</div> </div> <div class='people-content'> <div class='drag-div' v-for="ppdt in peopledata" @drop='drop($event)' @dragover='allowDrop($event)'> <div class='select-project-item'> <label class='drag-people-label'>{{ppdt.name}}:</label> </div> </div> </div> </div> <script type="text/javascript" src="js/vue.min2.js"></script> <script type="text/javascript"> var dom; var ss = new Vue({ 'el':'#dragCon', data:{ projectdatas:[{ id:1, name:'葡萄' },{ id:2, name:'芒果' },{ id:3, name:'木瓜' },{ id:4, name:'榴蓮' }], peopledata:[{ id:1, name:'小穎' },{ id:2, name:'hover' },{ id:3, name:'空巢青年三 ' },{ id:3, name:'一丟丟' }] }, mounted:function(){ this.$nextTick(function(){ }) }, watch:{ projectdatas:{ handler:function(val,oldval){ }, deep:true }, peopledata:{ handler:function(val,oldval){ }, deep:true } }, methods: { drag:function(event){ dom = event.currentTarget }, drop:function(event){ event.preventDefault(); event.target.appendChild(dom); }, allowDrop:function(event){ event.preventDefault(); } } }); </script> </body> </html>
實現(xiàn)效果:
到此,關(guān)于“vue2.0運(yùn)用原生js怎么實現(xiàn)拖拽元素功能”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。