【vue3】vue3 实践中遇到的问题

问题一

参考自:https://blog.csdn.net/qq_16559905/article/details/109819995

今天尝试用 vue 3 写个小 Demo,想写个路由(用的 vue-router: ^4.1.3),在修改 App.vue 文件这一步的时候,运行到 Google Chrome 就报错了:Uncaught TypeError: Cannot destructure property ‘options’ of ‘inject(…)’ as it is undefined.
或者报错提示信息为:Uncaught TypeError: Cannot destructure property ‘options’ of '(0 , vue__WEBP…

在这里插入图片描述

createWebHistory is not a function报错,这个是vue-router路由版本不匹配导致的
解决办法,安装地下版本的npm包:

Vue3.x vue-router4.x 写法,使用版本如下:
由原来的 mode: “history” 更改为 history: createWebHistory()(设置其他 mode 也是同样的方式)。

//安装版本
"vue": "^3.0.2",
"vue-loader": "^16.0.0-rc.1",
"vue-router": "^4.0.0-rc.3"

问题二

参考自:https://www.jianshu.com/p/b2b0f2acbba3
Vue 使用 eslint 后 Parsing error: Unexpected token <

在使用vue cli+eslint的时候,遇到如下问题:
error: Parsing error: Unexpected token < at src\views\index.vue:1:1:
> 1 | <template>
  2 |   <div class="index">
  3 |  </div>
解决办法:

1、在.eslint.js配置文件中添加如下配置:
(如果没有,新建.eslint.js文件)

module.exports = {
  root: true,
  parserOptions: {
    sourceType: 'module'
  },
  parser: "vue-eslint-parser",
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  rules: {
    'no-console': 'off',
  }
}

问题三

参考自:https://blog.csdn.net/dxnn520/article/details/125252353
【Vue】组件命名报错 “Component name “XXX“ should always be multi-word”的解决方法

  • 第一种解决方法:修改组件名称为大驼峰,不要用系统中命令常见的名称。
  • 第二种解决方法:
    在根目录下,打开【.eslintrc.js】文件,如果没有,就新建,输入以下内容(可能需要重启vscode)
    在这里插入图片描述
module.exports = {
    root: true,
    env: {
      node: true
    },
    'extends': [
      'plugin:vue/essential',
      'eslint:recommended'
    ],
    parserOptions: {
      parser: '@babel/eslint-parser'
    },
    rules: {
      'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
      'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
       //在rules中添加自定义规则
       //关闭组件命名规则
       "vue/multi-word-component-names":"off",
    },
    overrides: [
      {
        files: [
          '**/__tests__/*.{j,t}s?(x)',
          '**/tests/unit/**/*.spec.{j,t}s?(x)'
        ],
        env: {
          jest: true
        }
      }
    ]
  }
  
  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hzxOnlineOk

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值