首页 > 解决方案 > 将现有的 vue 项目转换为 nuxt.js

问题描述

我想将现有的 vuejs 项目转换为 nuxt.js 项目。为此,我创建了 nuxt.js 项目并将移动的文件移动到 nuxt 项目。我已复制 scr/view/layout 并粘贴到 layouts 文件夹中,vuex 将文件存储到 store 文件夹中。在 Layouts.vue 内部将这个标签更改为 this 。更新了 nuxt.config.js 文件,相应地添加了样式、模块和插件。更新了所有损坏的路径。

但是当我们尝试 npm run dev 时,它给出了错误。

错误示例

ERROR in ./assets/js/components/cookie.js
Module Error (from ./node_modules/eslint-loader/index.js):
ERROR in ./assets/js/components/cookie.js
Module Error (from ./node_modules/eslint-loader/index.js):
D:\VueJs-Projects\nuxtapp\assets\js\components\cookie.js
  9:29  error  Unnecessary escape character: \.  no-useless-escape
  9:37  error  Unnecessary escape character: \(  no-useless-escape
  9:39  error  Unnecessary escape character: \)  no-useless-escape
  9:41  error  Unnecessary escape character: \[  no-useless-escape
  9:47  error  Unnecessary escape character: \/  no-useless-escape
  9:49  error  Unnecessary escape character: \+  no-useless-escape
✖ 6 problems (6 errors, 0 warnings)
  [1]: https://i.stack.imgur.com/uCdLe.jpg

您可以在此处查看错误的详细信息。

标签: vue.jsnuxt.js

解决方案


这是因为您选择在 nuxt 应用程序中使用 ESLint,并且现有应用程序中的代码触发了“no-useless-escape”错误。

如果您知道发生错误的行(输出为您提供了此信息;看起来像 components 文件夹中 cookie.js 中的第 9 行是问题)您可以将该代码包装在以下内容中:


/* eslint-disable no-useless-escape */
... 
some code
...
/* eslint-enable no-useless-escape */

但是,我建议您选择与 Vue 应用程序相同的 linter,否则您可能会遇到其他类似的错误。


推荐阅读