hcg1023 / vue3-dnd

React Dnd implementation in Vue Composition-api.
https://www.vue3-dnd.com
MIT License
643 stars 52 forks source link

是否支持vue2.6+,且是js的项目 #37

Closed 130091064 closed 2 years ago

130091064 commented 2 years ago

如题,请问 是否支持vue2.6+,且是js的项目? 项目依赖:vue2.6.14 + js

我想用这个库,报错:

  1. inject() can only be used inside setup() or functional components.
  2. "Invariant Violation: Expected drag drop context"
hcg1023 commented 2 years ago

支持vue2.6,但是必须要使用 @vue/composition-api

hcg1023 commented 2 years ago

参考文档:https://hcg1023.github.io/vue3-dnd/guide/vue2.html

130091064 commented 2 years ago

@vue/composition-api 这个包引入了,但我的项目是js,不是ts, 在 useDrag 这步已经报错了,都还没走到 ref 那步。

hcg1023 commented 2 years ago

js或者ts没关系,可以看看代码怎么写的吗? 另外"Invariant Violation: Expected drag drop context"这个报错是因为没有使用DndProvider组件

130091064 commented 2 years ago

<a-modal class="common-modal" :maskClosable="false" title="添加表达式" :visible="true" :footer="null" width="1100px" :zIndex="999999" :destroyOnClose="true"

{{ system.title }} {{ device.title }}
{{ field.title }}

import { useDrag, DndProvider, useDrop } from 'vue3-dnd' import { ref } from '@vue/composition-api' import { HTML5Backend } from 'react-dnd-html5-backend'

created() { 下面这步已经报错 const [collect, drag] = useDrag(() => ({ type: 'FIELD', item: () => ({ name: props.name, }), end: (item, monitor) => { const dropResult = monitor.getDropResult() if (item && dropResult) { console.log(item) alert(You dropped ${item.name} into ${dropResult.name}!) } }, collect: (monitor) => ({ isDragging: monitor.isDragging(), handlerId: monitor.getHandlerId(), }), })) 下面这步没执行,阻塞了 console.log(collect, drag) this.fieldRef = ref()

drag(this.fieldRef)

}

hcg1023 commented 2 years ago

需要在setup函数中调用useDrag

130091064 commented 2 years ago

方便加qq吗? 刚放到setup中,还是报错: Injection "Symbol(DndContextType)" not found. Error in data(): "Invariant Violation: Expected drag drop context" Invariant Violation: Expected drag drop context

hcg1023 commented 2 years ago

这个就是因为没有包DndProvider组件

130091064 commented 2 years ago

我有在节点中包裹,App.vue中我也试过,都不行

hcg1023 commented 2 years ago

image 微信