如何让Webstorm 11在HTML脚本标签中识别ES2015 javascript [英] How to get Webstorm 11 to recognize ES2015 javascript in HTML script tags

查看:207
本文介绍了如何让Webstorm 11在HTML脚本标签中识别ES2015 javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当常规HTML中的脚本标签内部使用WebStorm 11时,我无法识别/突出显示/解析ES6 / ES2015 javascript。找不到适用于此的设置。感谢您的时间。

I've been having trouble getting WebStorm 11 to recognize/highlight/parse ES6/ES2015 javascript when it's inside script tags in regular HTML. Can't find a setting that seems to apply to this. Thanks in advance for your time.

例如,以下js在脚本标签内。你会注意到,WebStorm认为一大堆东西被打破了,但它执行得很好。

For example, the following js is inside a script tag. You'll notice that WebStorm thinks that a whole bunch of things are broken with it, but it executes just fine.

推荐答案

使用
<脚本类型=text / ecmascript-6> 而不是< script type =text / javascript> 应该可以帮助你。

Using <script type="text/ecmascript-6"> rather than <script type="text/javascript"> should help you.

关于JetBrans YouTrack的题目

Issue on JetBrans YouTrack on the topic.

它看起来像一个WebStorm错误(在最新版本上测试) :

It looks like a WebStorm bug (tested on the latest release):

  var a = (d) => {}; //OK
  a.v('c', (d) => {}); // OK
  class Test {
    doSmth(){
      a.sh('ff', (d) => {});
      //            ^^^^^^ , or ) expected when in <script>
      //            100% OK when in a js file
    }
  }

我想你可以联系JetBrains的支持,可能他们会解决它。

I think you could contact JetBrains support, probably they will fix it.

但无论如何,我不认为在HTML中有JS的好习惯,而且ES6尚未得到普遍的支持。

But anyways, I do not think it's a good practice to have JS in your HTML and, moreover, ES6 which is not yet commonly supported.

正如发表在 zigomir ,您可能需要使用 type =text / babel而不是 type =text / .vue 文件或其他文件不起作用。

As posted in comments by, zigomir, you might want to use type="text/babel" instead of type="text/ecmascript-6" in .vue files or otherwise linting wouldn't work.

这篇关于如何让Webstorm 11在HTML脚本标签中识别ES2015 javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆