安装jq
npm i jquery
<template>
<div>
<ul class="planWrap">
<li v-for="(item, index) in televisionList" :key="index">
<img
:id="item.id"
class="draggable"
draggable="true"
:src="require(`../assets/${item.id}.jpg`)"
:alt="item"
/>
<p class="libraryTextSize">{
{
item.name }}</p>
</li>
</ul>
<ul class="dragList dragList2">
<li
class="droppableEle dCerdraganddropname"
ref="claswqnameDc2"
data-index="11"
></li>
<li
class="droppableEle dCerdraganddropname"
ref="claswqnameDc2"
data-index="11"
></li>
<li
class="droppableEle dCerdraganddropname"
ref="claswqnameDc2"
data-index="11"
></li>
</ul>
</div>
</template>
<script>
import $ from "jquery";
export default {
name: "HelloWorld",
data() {
return {
list: [],
televisionList: [
{
name: "Vue",
id: "1",
},
{
name: "Vue",
id: "2",
},
{
name: "Vue",
id: "3",
},
],
};
},
created() {
setTimeout(() => {
this.initiateGame();
}, 300);
},
methods: {
initiateGame() {
this.draggableElements = document.querySelectorAll(".draggable");
this.droppableElements = document.querySelectorAll(".droppableEle");
this.draggableElements.forEach((elem) => {
elem.addEventListener("dragstart", this.dragStart);
});
this.droppableElements.forEach((elem) => {
elem.addEventListener("dragenter", this.dragEnter);
elem.addEventListener("dragover", this.dragOver);
elem.addEventListener("dragleave", this.dragLeave);
elem.addEventListener("drop"