在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ draggable拖拽和click點擊相關(guān)的問題

draggable拖拽和click點擊相關(guān)的問題

有一個需求就是,鼠標(biāo)點擊一側(cè)的標(biāo)簽之后,這個標(biāo)簽會在添加到另一側(cè)的數(shù)組里,而在此數(shù)組消失,如圖

圖片描述

圖片描述

在標(biāo)簽上綁定了click事件,但是當(dāng)標(biāo)簽到另一側(cè)的時候,標(biāo)簽內(nèi)部的click事件還是原來的事件,所以不會移回去。
這個應(yīng)該怎么辦?
而且點擊完之后報了很多錯誤,之前的拖拽也不可以了

我是用vue寫的,下面是部分代碼

模板代碼

<div class="custom_main_contents">
                    <div class="alreadypayattentionto_wrap">
                        <div class="custom_contents_title">
                            <span>已關(guān)注</span>
                        </div>
                        <div 
                            class="custom_contents" 
                            @drop="hasDrop($event)"
                              @dragover="hasDragOver($event)">
                              <draggable 
                                  v-model="follow_has_contents" 
                                  :options="{group:'people'}"
                                  class="custom_has_draggable">
                                <div
                                    class="custom_has_contents"
                                    v-for="(list,index) in follow_has_contents"
                                    draggable="true"
                                    @dragstart="hasDrag($event)"
                                    @click="joinHasContents($event,index)">
                                    <div class="contents_icon"></div>
                                    <div class="contents_main">
                                        <span>
                                            {{ list.name }}
                                        </span>
                                    </div>
                                </div>
                            </draggable>
                            <!-- 虛線框 -->
                            <div 
                                class="custom_has_contents"
                                v-show="showhasplacehoder">
                                <div class="content_placehoder"></div>
                            </div>
                            <div class="div_clear"></div>
                        </div>
                    </div>
                    <div class="notpayattentionto_wrap">
                        <div class="custom_contents_title">
                            <span>未關(guān)注</span>
                        </div>
                        <div 
                            class="custom_contents"
                            @drop="nohasDrop($event)"
                              @dragover="nohasDragOver($event)">
                              <draggable 
                                  v-model="follow_nohas_contents" 
                                  :options="{group:'people'}"
                                  class="custom_nohas_draggable">
                                <div
                                    class="custom_nohas_contents"
                                    v-for="(list,index) in follow_nohas_contents"
                                    draggable="true"
                                    @dragstart="nohasDrag($event)"
                                    @click="joinNoHasContents($event,index)">
                                    <div class="contents_icon"></div>
                                    <div class="contents_main">
                                        <span>
                                            {{ list.name }}
                                        </span>
                                    </div>
                                </div>
                            </draggable>
                            <!-- 虛線框 -->
                            <div 
                                class="custom_nohas_contents"
                                v-show="shownohasplacehoder">
                                <div class="content_placehoder"></div>
                            </div>
                            <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,
            }
        },
        methods: {
            /* 已關(guān)注的拖拽和釋放 */
            // 在區(qū)域內(nèi)釋放時觸發(fā)
            hasDrop: function(event){
                event.preventDefault(); // preventDefault()取消事件的默認(rèn)動作
                // 隱藏所有的虛框
                this.shownohasplacehoder=false;
                this.showhasplacehoder=false;
            },
            // 在區(qū)域內(nèi)觸發(fā)
            hasDragOver: function(event){
                event.preventDefault(); // preventDefault()取消事件的默認(rèn)動作
                this.showhasplacehoder=true; // 顯示區(qū)域內(nèi)的虛框
                this.shownohasplacehoder=false; // 隱藏區(qū)域外的虛框
            },

            /* 未關(guān)注的拖拽和釋放 */
            // 在區(qū)域內(nèi)釋放時觸發(fā)
            nohasDrop: function(event){
                event.preventDefault(); // preventDefault()取消事件的默認(rèn)動作
                // 隱藏所有的虛框
                this.showhasplacehoder=false;
                this.shownohasplacehoder=false;
            },
            // 在區(qū)域內(nèi)觸發(fā)
            nohasDragOver: function(event){
                event.preventDefault(); // preventDefault()取消事件的默認(rèn)動作
                this.shownohasplacehoder=true; // 顯示區(qū)域內(nèi)的虛框
                this.showhasplacehoder=false; // 隱藏區(qū)域外的虛框
            },

            /* 點擊事件 */
            joinHasContents: function(event,index){
                this.dom = event.currentTarget;
                $('.custom_nohas_draggable').append(this.dom);
                $(this.dom).addClass('custom_nohas_contents');
                $(this.dom).removeClass('custom_has_contents');
            },
            joinNoHasContents: function(event,index){
                this.dom = event.currentTarget;
                $('.custom_has_draggable').append(this.dom);
                $(this.dom).addClass('custom_has_contents');
                $(this.dom).removeClass('custom_nohas_contents');
            }
        },

報錯了

圖片描述

回答
編輯回答
墻頭草

大概思路是在put中拿到拖拽的內(nèi)容,然后保存成一個字段,在兩邊的框框中判斷這個字段是否存在,存在則顯示虛線框,內(nèi)容就是你保存的字段,然后在end函數(shù)中清空字段。注意設(shè)置.sortable-chosen這個class的display為none

2017年1月7日 14:56
編輯回答
尋仙

模板代碼沒有變,把點擊事件修改了一下,思路和一樓大神說的一樣,先往對側(cè)的數(shù)組push添加元素,然后再splice刪除元素。(vue數(shù)組的添加和刪除在我的筆記里面有)這些工作都是通過索引index來完成的

 /* 點擊事件 */
            joinHasContents: function(index){
                //this.dom = event.currentTarget;
                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.dom = event.currentTarget;
                this.follow_has_contents.push({name: this.follow_nohas_contents[index].name}); // 給對側(cè)的數(shù)組添加元素
                this.follow_nohas_contents.splice(index,1);
            }
2017年5月15日 18:09