Vue.js 3 模板-文字错误无法读取 null 的属性 'range'

标签 vue.js eslint vuejs3 dynamic-import async-components

我正在尝试在 Vue.js 中动态导入一个异步组件。

<template>
  <MyAsync></MyAsync>
</template>

<script>
import { defineAsyncComponent } from 'vue';

const component = 'lorem-ipsum-4';

export default {
  name: 'Article',
  components: {
    MyAsync: defineAsyncComponent(() => import(`@/articles/${component}.vue`)),
  },
};
</script>

然而,这不起作用并产生以下错误。
Failed to compile.

./src/views/Article.vue
Module build failed (from ./node_modules/eslint-loader/index.js):
TypeError: Cannot read property 'range' of null
Occurred while linting /project/src/views/Article.vue:13
    at SourceCode.getTokenBefore (/project/node_modules/eslint/lib/source-code/token-store/index.js:298:18)
    at checkSpacingBefore (/project/node_modules/eslint/lib/rules/template-curly-spacing.js:60:42)
    at TemplateElement (/project/node_modules/eslint/lib/rules/template-curly-spacing.js:119:17)
    at /project/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/project/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/project/node_modules/eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (/project/node_modules/eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (/project/node_modules/eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (/project/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at /project/node_modules/eslint/lib/linter/linter.js:936:32
    at Array.forEach (<anonymous>)
    at runRules (/project/node_modules/eslint/lib/linter/linter.js:931:15)
    at Linter._verifyWithoutProcessors (/project/node_modules/eslint/lib/linter/linter.js:1157:31)
    at /project/node_modules/eslint/lib/linter/linter.js:1281:29
    at Array.map (<anonymous>)
然而静态导入工作得很好:

<template>
  <MyAsync></MyAsync>
</template>

<script>
import { defineAsyncComponent } from 'vue';

export default {
  name: 'Article',
  components: {
    MyAsync: defineAsyncComponent(() => import('@/articles/lorem-ipsum-4.vue')),
  },
};
</script>

这是一个使用 Vue CLI 创建的 Vue.js v3 项目。
可以在 github 找到一个(相当少的)示例。
有没有办法让动态导入工作?

最佳答案

export default {
  name: 'Article',
  components: {
    MyAsync: defineAsyncComponent(() => import('@/articles/'+ component +'.vue')),
  },
};

但是,我不认为这很好。

关于Vue.js 3 模板-文字错误无法读取 null 的属性 'range',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66560841/

相关文章:

vue.js - Vue3 : i18n plugin won't find localization in json file

vue.js - pinia 在 Action 中使用 state 而不是 this

javascript - 使用Vue方法时访问数据时无法使用 "this"

vue.js - 如何在Vuetify中对齐组件内部的内容?

vue.js - 如何使用 Vuex 模块发布 Vue.js NPM 包?

node.js - npm 错误!安装 next.js 时

javascript - Vuejs _.orderBy 没有对 json 进行排序

reactjs - eslint 无法加载配置 "react-app"以从中扩展

sublimetext3 - 如何删除 Sublime Linter 中的弹出警告?

vue.js - 如何在 Vue 3 中获取数据?