猪肉丸
猪肉丸
  • 发布:2022-05-10 16:24
  • 更新:2024-08-13 18:15
  • 阅读:6546

(已完美解决)使用vuedraggable时,拖滑时发生错误,提示"TypeError: Cannot read property 'id' of null"

分类:uni-app

将node_modules下的vuedraggable插件抽离到其他目录去,可解决直接引入vuedraggable插件,拖滑时会爆如下错误

'报错截图'

听不明白?看如下详情说明

1. 这是vuedraggable插件的原始路径

/node_modlues/vuedraggable

'原始路径'

2. 这是vuedraggable插件的修改后路径

/common/node_modlues/vuedraggable

'修改后的路径'

3. main.js全局挂载组件

!不推荐,原始路径挂载方法(注意,这样做虽然是对的,但拖滑组件会报错,并且console.log无法打印回调信息)

import VueDraggable from 'vuedraggable'  
Vue.component('draggable', VueDraggable)

!推荐,修改后路径挂载方法(注意,必须这样做,才不会报错)

import VueDraggable from '@/common/node_modules/vuedraggable/src/vuedraggable'  
Vue.component('draggable', VueDraggable)

4. 最重要的一步,修改源码

在修改后路径的vuedraggable插件目录下修改vuedraggable.js的第30行代码


上面听不懂?行吧,路径为:/common/node_modules/vuedraggable/src/vuedraggable.js


vuedraggable.js #30

function emit(evtName, evtData) {    
  this.$nextTick(() => this.$emit(evtName.toLowerCase(), evtData));    
}

修改为

function emit(evtName, evtData) {    
  this.$nextTick(() => this.$emit(evtName.toLowerCase(), {...evtData}));    
}

参考的文章

上面两个文章只能解决临时问题,下次打开项目时,又得重新操作,过于麻烦,本文章的解决方法只需一次,下次打开项目时,无需再操作


虽然上面两个文章的解决方法并不太完美,但也不是说一点用都没有的,本文章在上面两个文章里进行了改进,解决度完美100%!

按照此文章方法,即可解决报错代码如下

chunk-vendors.js:2128 [Vue warn]: Error in v-on handler: "TypeError: Cannot read property 'id' of null"  

found in  

---> <Draggable>  
       at pages/index/index.vue  
warn @ chunk-vendors.js:2128  
e.config.errorHandler @ chunk-vendors.js:16585  
globalHandleError @ chunk-vendors.js:3387  
handleError @ chunk-vendors.js:3356  
invokeWithErrorHandling @ chunk-vendors.js:3379  
invoker @ chunk-vendors.js:3696  
invokeWithErrorHandling @ chunk-vendors.js:3371  
Vue.$emit @ chunk-vendors.js:5440  
(anonymous) @ chunk-vendors.js:12390  
(anonymous) @ chunk-vendors.js:3497  
flushCallbacks @ chunk-vendors.js:3423  
Promise.then (async)  
timerFunc @ chunk-vendors.js:3450  
nextTick @ chunk-vendors.js:3507  
Vue.$nextTick @ chunk-vendors.js:5073  
emit @ chunk-vendors.js:12389  
(anonymous) @ chunk-vendors.js:12402  
dispatchEvent @ chunk-vendors.js:35690  
_dispatchEvent @ chunk-vendors.js:35735  
_dragStarted @ chunk-vendors.js:36344  
setTimeout (async)  
_nextTick @ chunk-vendors.js:37371  
_onDragStart @ chunk-vendors.js:36566  
chunk-vendors.js:16585 [system] TypeError: Cannot read property 'id' of null  
    at s (chunk-vendors.js:16585)  
    at Proxy.l (chunk-vendors.js:16585)  
    at Proxy.t.$handleEvent (chunk-vendors.js:16585)  
    at start (pages-index-index.js:114)  
    at invokeWithErrorHandling (chunk-vendors.js:3371)  
    at VueComponent.invoker (chunk-vendors.js:3696)  
    at invokeWithErrorHandling (chunk-vendors.js:3371)  
    at VueComponent.Vue.$emit (chunk-vendors.js:5440)  
    at VueComponent.<anonymous> (chunk-vendors.js:12390)  
    at Array.<anonymous> (chunk-vendors.js:3497)
2022-05-10 16:24 负责人:无 分享
已邀请:

最佳回复

猪肉丸

猪肉丸 (作者)

文档看不懂?行吧!
下载我已经打包好的示例压缩包,解压后导入你的hx运行体验,已完美解决vuedraggable报错问题

兜兜ing

兜兜ing

[ subpackage-second/manage-subscriber-line-list/index.json 文件内容错误] subpackage-second/manage-subscriber-line-list/index.json: ["usingComponents"]["vuedraggable"] 未找到

7***@qq.com

7***@qq.com

vuedraggable插件小程序不支持吗,用HBuilderX运行到微信小程序的时候报未找到

4***@qq.com

4***@qq.com

我实现了APP端和 H5端的 各种兼容报错 APP端完美运行 小程序端未测试 大概率没问题
Cannot read property 'id' of null" 已解决
Cannot read property 'nid' of undefined at view.umd.min.js:1 已解决

  • 8***@qq.com

    你好,问一下app端 Cannot read property 'nid' of undefined at view.umd.min.js:1是怎么解决的啊

    2024-03-07 11:43

  • 卡卡她爹

    回复 8***@qq.com: 解决了吗???

    2024-08-28 16:35

祈愿稻荷神

祈愿稻荷神 - 刚毕业的社畜一枚

哈哈哈,这波算是送到嘴里吃了。

晴天i

晴天i

不支持APP?

2***@qq.com

2***@qq.com

厉害厉害,感谢

米花花

米花花

完美解决 牛逼 感谢

1***@qq.com

1***@qq.com

Error in nextTick: "TypeError: Invalid attempt to spread non-iterable instance 这又是啥问题

  • 1***@qq.com

    TypeError: Invalid attempt to spread non-iterable instance.

    In order to be iterable, non-array objects must have a [Symbol.iterator]() method.

    2024-08-14 09:25

  • 1***@qq.com

    解决了 用作者给的zip包 解压开替换掉 重新引入一下就好了

    2024-08-14 10:06

要回复问题请先登录注册