Vue.js 在vue中处理动态导入失败

Vue.js 在vue中处理动态导入失败,vue.js,dynamic,import,Vue.js,Dynamic,Import,我必须导入一些自定义组件,这些组件应该覆盖标准组件。 这些自定义组件与环境变量一起加载到包含这些客户端自定义组件的选定自定义文件夹中。 自定义组件不应该存在,因此我无法找到捕获动态导入失败的方法 我需要处理这种情况: const component = () => import('path_custom_not_existent..): if(!component) { component = () => import('path_standard_sure') } 因此,我不能

我必须导入一些自定义组件,这些组件应该覆盖标准组件。 这些自定义组件与环境变量一起加载到包含这些客户端自定义组件的选定自定义文件夹中。 自定义组件不应该存在,因此我无法找到捕获动态导入失败的方法

我需要处理这种情况:

const component = () => import('path_custom_not_existent..):
if(!component) {
component = () => import('path_standard_sure')
} 
因此,我不能覆盖每个客户端的所有组件,而只能覆盖我需要的组件

我试过用try/catch,但不起作用。 我尝试导入(…).then().catch(),但它仍然不起作用。 每次我使用路径错误的“导入”时,它都会显示“未找到模块:错误:无法解析…”

我使用的是composer.json(vue cli标准…)


你可以使用它的承诺:

const component = () => import('path_custom_not_existent..)
  .then((m) => m.default)
  .catch(err) => import ('404_component_does_not_exist)

你用的是什么?你可以看到。所以,只要你有巴别塔预设可用,你可以使用这种方法。你解决你的问题了吗?我也在寻找类似的东西
const component = () => import('path_custom_not_existent..)
  .then((m) => m.default)
  .catch(err) => import ('404_component_does_not_exist)