在vue3中使用datav完整引入时卡在加载页面的解决方法

发布于:2025-02-10 ⋅ 阅读:(50) ⋅ 点赞:(0)

文件修改

文件:node_modules/@dataview\datav-vue3/package.json

  // "module": "./es/index.js",
  "module": "./es/index.mjs",  // 修改后

使用完整引入,需要为datav配置文件添加相应方法

文件:node_modules/@dataview\datav-vue3/es/index.mjs

// 全局注册方法
// 存在问题,未对setClassPrefix方法处理
// D、E、G...符号代表BorderBox1、BorderBox10、BorderBox11...组件名称
export default {
  install: (app, options) => {
    const components = [
	  D,
	  E,
	  G,
	  I,
	  K,
	  g,
	  C,
	  P,
	  h,
	  k,
	  u,
	  w,
	  z,
	  N,
	  Q,
	  S,
	  U,
	  W,
	  Y,
	  _,
	  oo,
	  eo,
	];
	components.map((component) => {
		app.component(component.name, component);
	});
  }
}

在utils中添加文件datav.js

import * as DataV from '@dataview/datav-vue3';

// 随便写即可
export default function (app) {
  const module = Object.keys(DataV);
  for (const m of module) {
    if (m === 'Loading') continue; // 因为项目饿了么注册过这个组件,就不用datav提供的,跳过本次循环
    app.component(DataV[m].name, DataV[m]);
  }
}

main.js中全局引入修改:

import DataV from '@/utils/datav';
const app = createApp(App)
app.use(DataV);

在这里插入图片描述
即可解决!

若出现TypeError: Cannot read properties of null (reading ‘$el’)报错:

1、先参考这篇文章对应问题操作:
Vue2使用datav3报错的三个问题解决

2、再根据这篇文章步骤操作:
若依vue使用DataV设计大屏报错多是版本问题

报错问题Failed to execute ‘removeChild’ on ‘Node’: The node to be removed is not a child of this node,参考这篇文章的解决方法:

datav+vue3 引用报错,跳转页面报错,DOMException: Failed to execute ‘removeChild‘ on ‘Node‘: The node to be remov

解决上述两种报错以后,使用vue3编程式导航实现页面跳转时不会再出现问题!