vue中问题-错误总结

本文总结了在Vue.js开发中遇到的一些常见错误,包括template标签的错误、项目运行卡死、axios请求500及CROC错误、eslint报错等,并提供了相应的解决策略,指出许多问题源于eslint校验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1:template标签-报下面的错误

 

TypeScript intellisense is disabled on template. To enable,
 configure `"jsx": "preserve"` in the `"compilerOptions"` 
property of tsconfig or jsconfig. To disable this prompt
 instead, configure `"experimentalDisableTemplateSupport": true` in `"
vueCompilerOptions"` property.
 

原因:Vue Language Features插件问题,

解决办法:添加:"jsx": "preserve",    //在这里添加"jsx": "preserve",

解决办法,找到文件 jsconfig.json

将这段代码复制进去:

{
  "compilerOptions": {
    "target": "es5",
    "module": "esnext",
    "baseUrl": "./",
    "jsx": "preserve",    //在这里添加"jsx": "preserve",
    "moduleResolution": "node",
    "paths": {
      "@/*": [
        "src/*"
      ]
    },
    "lib": [
      "esnext",
      "dom",
      "dom.iterable",
      "scripthost"
    ]
  }
}
 

2:遇到 运行项目卡起不运行?

原因:在使用vue中,还是个html风格?标签原因哦,在main.js中是否有

Vue.config.productionTip = false //关闭提示

解决方法:

<!--在响应的vue中使劲查看标签是否成对!!!-->
<!-- 错误写法-->
<template>
<template>
</template>
<template>
</template>
</template>

<!-- 正确写法-->
<template>
<div>
<template>
</template>
<template>
</template>
</div>
</template>

3:在使用axios中.出现报500 ,CROC等错误

原因:没有跨域,或者服务端(php)错误

解决方法

// 前端:在mian.js中 或者在你axios的其他地方

//Axios
import http from 'axios'
import './Api/config'
http.defaults.baseURL="https://xxx.com/index.php/"//跨域


//保险起见!前端使用QS 对其封装,请求数据
import Qs from "qs"; //用npm 或cnpm 安装QS
 
var configs={headers:{"Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"}}
this.$http.post('xxx.com/xxx.php',Qs.stringify({action:'ChenpinmoData',},configs))



//后端:申明格式 如果使用的tp框架在public>index.php中

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST,GET');
header('Access-Control-Allow-Credentials:true');
header("Access-Control-Allow-Headers:Accept,Referer,User-Agent,X-Requested-With,Content-Type,token");


//举个例子,后端获取数据,
$action=request()->post('action');
$action=request()->get('action');
//或者
$action=$_POST['action'];

4:在vue js中报错 Delete `␍`eslint 

原因:整个vue js都是红色的?原因插件问题!

解决方法:

执行命令:
yarn run lint --fix   


处理方法2
如果存在.prettierrc文件添加如下配置
"endOfLine": "auto"
如果不存在该文件 打开vscode编辑器的setting.json文件添加如下配置
"prettier.endOfLine": "auto", // 结尾是 auto

5:打开vue 中出现 Component name "XXXXX" should always be multi-word

原因:还是插件问题!

解决方法:

vue.config.js文件中写入lintOnSave:false,修改完毕后重启项目即可

6问题总结下:

许多问题都是eslint校验 在搞鬼!那么怎么才能 避免?

报错一:
ESLint: Missing return type on function.(@typescript-eslint/explicit-module-boundary-types)

解决方法:在.eslintrc.js 里面 加上

 "rules": {
     "@typescript-eslint/explicit-module-boundary-types": "off"  
  },
1
2
3
报错二:
ESLint: Type string trivially inferred from a string literal, remove type annotation.(@typescript-eslint/no-inferrable-types)

解决方法:在.eslintrc.js 里面 加上

 "rules": {
     "@typescript-eslint/no-inferrable-types": "off"   
  },
1
2
3
报错三:
ESLint: Require statement not part of import statement. eslint@typescript-eslint/no-var-requires

解决方法:在.eslintrc.js 里面 加上

 "rules": {
    '@typescript-eslint/no-var-requires': 0 
  },
1
2
3
报错四:
ESLint: Forbidden non-null assertion.(@typescript-eslint/no-non-null-assertion)

解决方法:在.eslintrc.js 里面 加上

 "rules": {
    '@typescript-eslint/no-non-null-assertion': 'off'
  },
1
2
3
报错五:
ESLint: ‘xxx’ is not defined.(no-undef) //说明全局变量未定义

解决方法:在.eslintrc.js 里面 添加代码块

 "rules": {
    ...
  },
    "globals":{
    "xxx": true//xxx 为你的全局变量
  }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

加金开发

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

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

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

打赏作者

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

抵扣说明:

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

余额充值