用draggable組件寫了這部分功能,但是遇到了一些問題,請大神們指教
首先來說,這部分的需求是把一側(cè)的標(biāo)簽拖拽到另一側(cè)的數(shù)組中。
但是只能把標(biāo)簽拖到數(shù)組中才可以,如下圖這樣才可以
虛線框是綁定了一個動態(tài)的class屬性,(:class="nowclicknohas===index ? 'custom_draggable' : ''"),當(dāng)拖拽起的時候觸發(fā)@dragstart="nohasDrag(index)",把拖拽元素的索引賦值給變量nowclicknohas或nowclickhas,然后動態(tài)class屬性是一個三元運算符進行判斷。當(dāng)釋放拖拽的時候觸發(fā)@drop="nohasDrop()",把變量nowclicknohas或nowclickhas設(shè)置為空。
但是如果如下圖的拖拽方法,沒有拖拽到數(shù)組中,而是拖拽到了數(shù)組的下方,但是也在數(shù)組的div標(biāo)簽內(nèi)。這樣拖拽的話,拖住愛的數(shù)組就過不去,如下第二個圖
我是用vue寫的
模板代碼
<div class="custom_main_contents">
<div
class="alreadypayattentionto_wrap"
@drop="hasDrop()"
@dragover="hasDragOver()">
<div class="custom_contents_title">
<span>已關(guān)注</span>
</div>
<div
class="custom_contents">
<draggable
v-model="follow_has_contents"
:options="{group:'people'}"
class="custom_has_draggable">
<div
class="custom_has_contents"
:class="nowclickhas===index ? 'custom_draggable' : ''"
v-for="(list,index) in follow_has_contents"
draggable="true"
@dragstart="hasDrag(index)"
@click="joinHasContents(index)">
<div class="contents_icon"></div>
<div class="contents_main">
<span class="contents_main_text">
{{ list.name }}
</span>
</div>
</div>
</draggable>
<div class="div_clear"></div>
</div>
</div>
<div
class="notpayattentionto_wrap"
@drop="nohasDrop()"
@dragover="nohasDragOver()">
<div class="custom_contents_title">
<span>未關(guān)注</span>
</div>
<div
class="custom_contents">
<draggable
v-model="follow_nohas_contents"
:options="{group:'people'}"
class="custom_nohas_draggable">
<div
class="custom_nohas_contents"
:class="nowclicknohas===index ? 'custom_draggable' : ''"
v-for="(list,index) in follow_nohas_contents"
draggable="true"
@dragstart="nohasDrag(index)"
@click="joinNoHasContents(index)">
<div class="contents_icon"></div>
<div class="contents_main">
<span class="contents_main_text">
{{ list.name }}
</span>
</div>
</div>
</draggable>
<div class="div_clear"></div>
</div>
</div>
</div>
js部分代碼
data(){
return{
follow_has_contents: [
{ name: '我的導(dǎo)航' },
{ name: '我的星座' }
],
customNow: false,
follow_nohas_contents: [
{ name: '我的股票' },
{ name: '我的小說' }
],
dom: '',
/* 虛框 */
showhasplacehoder: false,
shownohasplacehoder: false,
nowclickhas: '',
nowclicknohas: ''
}
},
components: {
dropfollow,
draggable
},
methods: {
/* 已關(guān)注的拖拽和釋放 */
// 拖拽元素時觸發(fā)
hasDrag: function(index){
this.nowclickhas=index;
},
// 在區(qū)域內(nèi)釋放時觸發(fā)
hasDrop: function(){
// 隱藏所有的虛框
this.shownohasplacehoder=false;
this.showhasplacehoder=false;
this.nowclickhas='';
},
// 在區(qū)域內(nèi)觸發(fā)
hasDragOver: function(){
this.showhasplacehoder=true; // 顯示區(qū)域內(nèi)的虛框
this.shownohasplacehoder=false; // 隱藏區(qū)域外的虛框
},
/* 未關(guān)注的拖拽和釋放 */
// 拖拽元素時觸發(fā)
nohasDrag: function(index){
this.nowclicknohas=index;
},
// 在區(qū)域內(nèi)釋放時觸發(fā)
nohasDrop: function(){
// 隱藏所有的虛框
this.showhasplacehoder=false;
this.shownohasplacehoder=false;
this.nowclicknohas='';
},
// 在區(qū)域內(nèi)觸發(fā)
nohasDragOver: function(){
this.shownohasplacehoder=true; // 顯示區(qū)域內(nèi)的虛框
this.showhasplacehoder=false; // 隱藏區(qū)域外的虛框
},
/* 點擊事件 */
joinHasContents: function(index){
this.follow_nohas_contents.push({name: this.follow_has_contents[index].name}); // 給對側(cè)的數(shù)組添加元素
this.follow_has_contents.splice(index,1);
},
joinNoHasContents: function(index){
this.follow_has_contents.push({name: this.follow_nohas_contents[index].name}); // 給對側(cè)的數(shù)組添加元素
this.follow_nohas_contents.splice(index,1);
}
}北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國家
達內(nèi)教育集團成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機構(gòu),是中國一站式人才培養(yǎng)平臺、一站式人才輸送平臺。2014年4月3日在美國成功上市,融資1
北大課工場是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國家深化產(chǎn)教融合/校企合作的政策,積極推進“中國制造2025”,實現(xiàn)中華民族偉大復(fù)興的升級產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項目經(jīng)理從事移動互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負責(zé)iOS教學(xué)及管理工作。
浪潮集團項目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺面向?qū)ο箝_發(fā)經(jīng)驗,技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點難點突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫,具有快速界面開發(fā)的能力,對瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁制作和網(wǎng)頁游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗。曾經(jīng)歷任德國Software AG 技術(shù)顧問,美國Dachieve 系統(tǒng)架構(gòu)師,美國AngelEngineers Inc. 系統(tǒng)架構(gòu)師。