vue 常见报错问题

情况一:http://eslint.org/docs/rules/no-tabs  Unexpected tab character

解决方案:缩进是4个空格,而不是tab,设置indent

情况二 : $ npm run dev 运行报错 

 解决方案:该问题是因为脚手架工具默认监听的是8080端口,此时是8080端口被占用情况导致的。

A.找出8080端口占用进程然后杀死

执行 $ lsof -i :8080

COMMAND PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
httpd    79  root    6u  IPv6 0x16935b8002e27567      0t0  TCP *:http-alt (LISTEN)

执行sudo kill -9 79 

再执行 npm run dev,然后搭建成功.

B.修改config 配置

情况三: http://eslint.org/docs/rules/eol-last Newline required at end of file but not found

解决方案:结尾 需要空一行

情况四: http://eslint.org/docs/rules/no-tabs  Unexpected tab character

解决方案: 删除行前空格

情况五: Uncaught TypeError: router.map is not a function

解决方案: vue router 2.0 没有map这个方法了,直接在new router的时候传入

      npm install vue-router@0.7.13 兼容1.0版本vue

情况六: $ npm install node-sass --save-dev 失败

解决方案: $ npm install node-sass --registry=http://registry.npm.taobao.org

 

设置镜像的2种方法:

1、命令行安装:

npm config set registry http://registry.cnpmjs.org
npm info underscore 

2、直接编辑node安装目录下的npmrc文件,我的文件路径在:C:\Program Files (x86)\nodejs\node_modules\npm

用记事本打开,在最后添加一行:registry = http://registry.cnpmjs.org

情况七: Failed at the chromedriver@2.27.3 install script 'node install.js'.

解决方案: $ npm install chromedriver -g

情况八: Failed at the phantomjs-prebuilt@2.1.14 install script 'node install.js

解决方案: npm install phantomjs-prebuilt@2.1.14 --ignore-scripts

情况九: http://eslint.org/docs/rules/linebreak-style  Expected linebreaks to be 'LF' but found 'CRLF'

解决方案:方案1. /*eslint linebreak-style: ["error", "windows"]*/

     方案2. 修改根路径下 .eslintrc.js 的配置 

module.exports = {
    "root": true,
    "parserOptions": {
        "sourceType": "module",
        "ecmaVersion": 6
    },
    "rules": {
        // windows linebreaks when not in production environment
        "linebreak-style": ["error", process.env.NODE_ENV === 'prod' ? "unix" : "windows"]
    }
};

情况十: Media query expression must begin with '('

解决方案:

情况十一:
vue报错cannot GET
解决方案:  你init vue-cli的时候,有个选项问你是否需要eslint可以选择不需要,因为它是检验的,可以不用,如果用它格式写的不规范启不来页面

情况十二:

解决方案:
### Vue3 报错解决方案 在开发过程中遇到 Vue3 的报错问题,通常可以通过以下几个方面来排查并解决问题。 #### 1. 创建项目时报错 如果通过命令 `vue create runoob-vue3-app` 创建项目时发生错误,可能的原因包括 Node.js 版本不兼容、npm 或 yarn 配置不当等问题。可以尝试以下方法解决: - **更新 Node.js 和 npm**:确保安装的是最新版本的 Node.js 和 npm,因为旧版可能会导致依赖解析失败[^1]。 ```bash node -v && npm -v ``` - 如果发现版本过低,建议升级到 LTS 版本: ```bash nvm install --lts nvm use --lts ``` - 使用 Yarn 替代 npm 安装依赖也可能有助于减少冲突: ```bash yarn global add @vue/cli vue create runoob-vue3-app cd runoob-vue3-app yarn serve ``` --- #### 2. 导入模块时报错 (Warn: import Vue from ‘vue’) 当使用 Vue CLI 构建项目时,如果出现类似警告或错误提示 `import Vue from 'vue'`,这通常是由于 Vue3 中移除了默认导出方式所致。Vue3 不再支持全局导入 Vue 对象的方式[^2]。 - 修改代码中的导入语句为解构形式即可修复此问题: ```javascript // 错误写法(适用于 Vue2) import Vue from 'vue' // 正确写法(适用于 Vue3) import { createApp } from 'vue' const app = createApp(App).mount('#app') ``` --- #### 3. VSCode 保存文件时报错 VSCode 编辑器中保存 Vue 文件时常因 ESLint 格式化工具引发报错。这类问题是由于编辑器设置与项目的 ESLint 配置不符引起的[^3]。 - 确认 `.eslintrc.js` 是否存在以及其配置是否正确。以下是常见的配置示例: ```javascript module.exports = { root: true, env: { node: true, }, extends: [ 'plugin:vue/vue3-essential', '@vue/standard', ], rules: { 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off', }, } ``` - 同步调整 VSCode 设置,在 `settings.json` 添加如下内容以匹配项目需求: ```json { "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "eslint.validate": ["javascript", "javascriptreact", "typescript", "vue"], "[vue]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" } } ``` --- #### 4. TypeScript 文件引用 Vue 组件时报错 对于基于 Vite 的 Vue3 项目,TypeScript 可能无法识别 `.vue` 扩展名作为合法模块。这种情况下需要手动声明扩展名的支持[^4]。 - 在根目录下的 `vite-env.d.ts` 文件或其他自定义 TS 类型文件中加入以下声明: ```typescript declare module '*.vue' { import { DefineComponent } from 'vue' const component: DefineComponent<{}, {}, any> export default component } ``` 上述声明告诉 TypeScript 将所有 `.vue` 文件视为组件对象处理,从而消除潜在的编译错误。 --- ### 总结 以上方案涵盖了创建项目、模块导入、IDE 工具链适配以及类型声明等多个方面的常见问题及其对应解决策略。具体实施需根据实际场景逐一验证效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值