1***@qq.com
1***@qq.com
  • 发布:2024-11-20 12:44
  • 更新:2024-11-20 14:04
  • 阅读:38

[Vue warn]: Error in nextTick: "TypeError: Cannot read property 'dataset' of null"

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Mac

PC开发环境操作系统版本号: macOS Sequoia 15.1

第三方开发者工具版本号: 2.0.2-4000820240401001

基础库版本号: 3.6.6

项目创建方式: CLI

CLI版本号: ~4.5.0

示例代码:
this.$nextTick(() => {  
  console.log('打印了组件变量值:', this.$refs.MyComponent.X)  
})

操作步骤:

点击点我进入A包

预期结果:

不报错,能打印出1

实际结果:

报错
[Vue warn]: Error in nextTick: "TypeError: Cannot read property 'dataset' of null"
(found in packageA/pages/pageA/index.vue)

bug描述:

项目配置分包,小程序中分包A中A页面使用分包B中的组件,A页面配置了componentPlaceholder。
在A的onLoad周期中使用$nextTick获取组件内部的值报错。
[Vue warn]: Error in nextTick: "TypeError: Cannot read property 'dataset' of null"
(found in packageA/pages/pageA/index.vue)

2024-11-20 12:44 负责人:无 分享
已邀请:
1***@qq.com

1***@qq.com (作者) - 隔壁小王同学

1***@qq.com

1***@qq.com (作者) - 隔壁小王同学

/packageA/index.vue  

<template>  
...  
<MyComponent ref="MyComponent"></MyComponent>  
...  
</template>  

...  
<script>  
...  
import MyComponent from '@/packageB/components/MyComponent/MyComponent.vue'  
...  
...  
 onLoad() {  
    this.$nextTick(() => {  
      console.log('打印了组件变量值:', this.$refs.MyComponent.X)  
    })  
  },  
...  
</script>
/packageB/components/MyComponent/MyComponent.vue  

<template>  
...  
</template>  
<script>  
...  
data  () {  
    return {  
      X: 1  
    }  
  },  
...  
</script>
pages.json  

...  
{  
  "path": "pages/pageA/index",  
  "style": {  
    "navigationBarTitleText": "A页面",  
    "componentPlaceholder": {  
      "my-component": "view"  
    }  
  }  
},  
...

要回复问题请先登录注册