vue中使用jquery报错 $ is not defined - Go语言中文社区

vue中使用jquery报错 $ is not defined


一、问题  $ is not defined

在使用Vs Code编写Vue应用的时候,从页面中引入jquery后,在.vue文件编写使用时,ESLint编译报错,程序运行正常。

错入内容如下:

error: Unexpected console statement (no-console) at srccomponentsHelloWorld.vue:16:7:
  14 |   methods: {
  15 |     getOne: function() {
> 16 |       console.info("click");
     |       ^
  17 |       $.get("http://www.gongjuji.net", function(data) {
  18 |         console.info(data);
  19 |       });


error: '$' is not defined (no-undef) at srccomponentsHelloWorld.vue:17:7:
  15 |     getOne: function() {
  16 |       console.info("click");
> 17 |       $.get("http://www.gongjuji.net", function(data) {
     |       ^
  18 |         console.info(data);
  19 |       });
  20 |     }

二、错误原因和解决方案

在VS Code编写Vue代码时使用ESLint编译js源代码,针对不同的环境代码检查方式不同。

方式1.修改ESLint的检查环境,增加jquery即可。推荐

  "eslintConfig": {
    "root": true,
    "env": {
      "browser":true,
      "node": true,
      "jquery": true
    },

 

  "eslintConfig": {
    "root": true,
    "env": {
      "node": true,
      "jquery":true
    },

2.设ESLint规则,忽略指定错误,例如no-console

  "eslintConfig": {
    "extends": "eslint:recommended",
    "env": {
      "node": true
    },
    "rules": {
      "no-console": "off"
    }
  }

 

 

更多:

 Vue开发异常: Error: custom keyword definition is invalid: data.errors should be boolean

基于Vue的手机端UI框架整理

Vue 引用全局样式

转载于:https://my.oschina.net/tianma3798/blog/3009722

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/weixin_33834628/article/details/92504700
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-05-31 01:35:39
  • 阅读 ( 1733 )
  • 分类:前端

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢