【问题标题】:How to integrate WebStorm with Vue.js如何将 WebStorm 与 Vue.js 集成
【发布时间】:2016-04-29 04:10:42
【问题描述】:

WebStorm 本身不支持 Vue.js(至少现在 - 2016 年 4 月)。

我发现了一些关于如何改善 WebStorm 体验的建议。 现在我想在一个地方列出它们(我将在下面回答我自己的问题)。

随时改进答案

【问题讨论】:

    标签: intellij-idea phpstorm webstorm vue.js jetbrains-ide


    【解决方案1】:

    WebStorm 现在支持 vue.js(从 2017.1 [blog] 开始)

    所以不需要额外的步骤


    已弃用

    这是改善 WebStorm(PhpStorm、Idea 等)体验的方法清单:

    1. 使用 Vue.js 插件。

    更新:两个插件都有自己的问题atm

    您可以通过Settings(Preferences) => Plugins => Browse repositories => 安装它(搜索)“vue”

    选择一个或两个:“Vue.js”或“vue-for-idea”。这取决于你。

    1. 将“Javascript 语言版本”设置为 ES6。

    打开Settings(Preferences) => Language & Frameworks => JavaScript。将Javascript Language Version 设置为ECMAcript6

    https://github.com/postalservice14/vuejs-plugin

    1. 改进 HTML-tag 的属性高亮

    打开Settings(Preferences) => Editor => Inspection => HTML => 选择Unknown HTML tag attributes => 点击Custom HTML tag attributes。 添加你的属性。

    比如我的清单:

    v-on,v-on:click,v-on:change,v-on:focus,v-on:blur,v-on:keyup,:click,@click,v-model,v-text ,v-bind,:disabled,@submit,v-class,:class,v-if,:value,v-for,scoped,@click.prevent,number,:readonly,@input,@click,v-show ,v-else,readonly,v-link,:title,:for,tab-index,:name,:id,:checked,transition,@submit.prevent,autocapitalize,autocorrect,slot,v-html,:style

    附:有关自定义标签的完整列表,请查看下面的 @Alex's 答案

    P.P.S.实际上它应该以更常见的方式工作:

    打开Settings(Preferences) => Languages & Frameworks => Javascript => Libraries => 点击Add (在此之后,您应该将路径设置为vue.js。您可以使用 npm 或其他方式下载它)

    (此答案中的更多信息:https://stackoverflow.com/a/28903910/930170)

    但我没有成功。

    1. 启用 Node.js 编码辅助:

    打开Settings(Preferences) => Languages & Frameworks => Node.js and NPM

    如果“Node.js核心库未启用”,点击按钮Enabled


    已弃用(如果您不使用 IDE 的 vue 插件,则可能需要):

    1. 使*.vue 文件被识别为html 苍蝇。

    打开Settings(Preferences) => Editor =>File Types 在里面找到HTML Recognized File Types,然后添加 *.vue 作为新注册 模式。

    1. 改进 ES6 突出显示。

    在每个带有标签的vue文件中:

        <script type="text/babel">
            // your code here...
        </script>
    

    (这将有助于识别像 setTimeout(() =&gt; {console.log(1) }, 100) 这样的结构)

    1. 改进样式突出显示。 (sass、scss 等)

    在每个带有标签的vue文件中:

        <style lang="sass" rel="stylesheet/sass">
            // your style here...
        </style>
    

    对于scss,它将是&lt;style lang="scss" type="text/scss"&gt;

    对于stylus,请尝试&lt;style lang="stylus" type="text/stylus"&gt;


    UPD:以下步骤不太可信,它们可能有帮助,也可能没有,其中一些我没有亲自检查,或者我没有catch 是否存在任何效果。

    1. 导入 TextMate Bundle 功能。

    https://www.jetbrains.com/help/phpstorm/2016.1/textmate-bundles.html?origin=old_help

    1. 为 vue 导入 TypeScript 表格。

    打开Settings(Preferences) => Language &amp; Frameworks => JavaScript => Libraries。点击Download,切换到TypeScript community stubs。并下载带有vue字的所有标签。

    示例:https://youtu.be/4mKiGkokyx8?t=84(从 1:24 开始)


    UPD2:如需更多信息,请查看 github 上的问题:https://github.com/vuejs/vue-syntax-highlight/issues/3


    UPD3:常见问题解答:

    1. 我可以改进pug(jade) 突出显示吗?

      • 否。因为 Webstorm 不支持模板语言注入...Issue 自 2013 年以来一直没有官方消息。

    【讨论】:

    • 诀窍&lt;style lang="sass" rel="stylesheet/sass"&gt; 对我不起作用。即使设置 lang="scss" 也无济于事,它会尝试读取纯 css,所以它充满了错误。此外,它会弄乱自动缩进。你确定这个还是我错过了什么?编辑:刚刚发现它应该可以工作youtrack.jetbrains.com/issue/WEB-14762
    • 哦,想通了。 &lt;style lang="scss" type="text/scss" scoped&gt;&lt;/style&gt; 对我有用。
    • 为了提高 HTML 标记的属性突出显示,请注意 XML 检查,这可能会导致 html 检查出现问题。
    • 感谢您进行详尽的分析,这是一个很大的帮助。但是,由于您所说的原因,这两个插件在 WebStorm 中都不是很好。出于某种原因,额外的 HTML 标记属性列表也没有任何区别。 所做 的工作是将 .vue 文件分配给 HTML,然后使用 vue 简写 - 即 @ 而不是 v-on,而只是 ':' 而不是 v-bind。但是我更喜欢 v-on 而不是 @,因为它说明了它在做什么。
    • 这里有人知道如何修改模板区域的默认制表符缩进间距吗?使用 vue.js 插件,一切都很好,但我无法将制表符间距从 4 更改为 2。样式也是如此。只有脚本区域读取制表符间距设置。
    【解决方案2】:

    我更新了未知 HTML 标记列表,因此您只需将其复制粘贴到 PhpStorm 设置中即可:

    nobr, noembed, comment, noscript, embed, script, :checked, :class, :click, :disabled, :for, :id, :name, :readonly, :style, :title, :value, @click, @click.prevent, @click.stop, @click.capture, @click.self, @drag, @drag.prevent, @drag.stop, @drag.capture, @drag.self, @dragend, @dragend.prevent, @dragend.stop, @dragend.capture, @dragend.self, @dragenter, @dragenter.prevent, @dragenter.stop, @dragenter.capture, @dragenter.self, @dragleave, @dragleave.prevent, @dragleave.stop, @dragleave.capture, @dragleave.self, @dragover, @dragover.prevent, @dragover.stop, @dragover.capture, @dragover.self, @dragstart, @dragstart.prevent, @dragstart.stop, @dragstart.capture, @dragstart.self, @drop, @drop.prevent, @drop.stop, @drop.capture, @drop.self, @input, @input.prevent, @input.stop, @input.capture, @input.self, @submit, @submit.prevent, @submit.stop, @submit.capture, @submit.self, scoped, slot, tab-index, v-bind, v-class, v-else, v-for, v-html, v-if, v-link, v-model, v-on, v-on:input, v-on:input.prevent, v-on:input.stop, v-on:input.capture, v-on:input.self, v-on:submit, v-on:submit.prevent, v-on:submit.stop, v-on:submit.capture, v-on:submit.self, v-on:blur, v-on:blur.prevent, v-on:blur.stop, v-on:blur.capture, v-on:blur.self, v-on:change, v-on:change.prevent, v-on:change.stop, v-on:change.capture, v-on:change.self, v-on:click, v-on:click.prevent, v-on:click.stop, v-on:click.capture, v-on:click.self, v-on:focus, v-on:focus.prevent, v-on:focus.stop, v-on:focus.capture, v-on:focus.self, v-on:keypress, v-on:keypress.prevent, v-on:keypress.stop, v-on:keypress.capture, v-on:keypress.self, v-on:keyup, v-on:keyup.prevent, v-on:keyup.stop, v-on:keyup.capture, v-on:keyup.self, v-on:keyup.enter, v-on:keyup.enter.prevent, v-on:keyup.enter.stop, v-on:keyup.enter.capture, v-on:keyup.enter.self, v-on:keyup.tab, v-on:keyup.tab.prevent, v-on:keyup.tab.stop, v-on:keyup.tab.capture, v-on:keyup.tab.self, v-on:keyup.delete, v-on:keyup.delete.prevent, v-on:keyup.delete.stop, v-on:keyup.delete.capture, v-on:keyup.delete.self, v-on:keyup.esc, v-on:keyup.esc.prevent, v-on:keyup.esc.stop, v-on:keyup.esc.capture, v-on:keyup.esc.self, v-on:keyup.space, v-on:keyup.space.prevent, v-on:keyup.space.stop, v-on:keyup.space.capture, v-on:keyup.space.self, v-on:keyup.up, v-on:keyup.up.prevent, v-on:keyup.up.stop, v-on:keyup.up.capture, v-on:keyup.up.self, v-on:keyup.down, v-on:keyup.down.prevent, v-on:keyup.down.stop, v-on:keyup.down.capture, v-on:keyup.down.self, v-on:keyup.left, v-on:keyup.left.prevent, v-on:keyup.left.stop, v-on:keyup.left.capture, v-on:keyup.left.self, v-on:keyup.right, v-on:keyup.right.prevent, v-on:keyup.right.stop, v-on:keyup.right.capture, v-on:keyup.right.self, v-show, v-text, v-on:drag, v-on:drag.prevent, v-on:drag.stop, v-on:drag.capture, v-on:drag.self, v-on:dragend, v-on:dragend.prevent, v-on:dragend.stop, v-on:dragend.capture, v-on:dragend.self, v-on:dragenter, v-on:dragenter.prevent, v-on:dragenter.stop, v-on:dragenter.capture, v-on:dragenter.self, v-on:dragleave, v-on:dragleave.prevent, v-on:dragleave.stop, v-on:dragleave.capture, v-on:dragleave.self, v-on:dragover, v-on:dragover.prevent, v-on:dragover.stop, v-on:dragover.capture, v-on:dragover.self, v-on:dragstart, v-on:dragstart.prevent, v-on:dragstart.stop, v-on:dragstart.capture, v-on:dragstart.self, v-on:drop, v-on:drop.prevent, v-on:drop.stop, v-on:drop.capture, v-on:drop.self, @focus, @focus.prevent, @focus.stop, @focus.capture, @focus.self, @change, @change.prevent, @change.stop, @change.capture, @change.self, @blur, @blur.prevent, @blur.stop, @blur.capture, @blur.self, @keypress, @keypress.prevent, @keypress.stop, @keypress.capture, @keypress.self, @keyup, @keyup.prevent, @keyup.stop, @keyup.capture, @keyup.self, v-on:reset, v-on:reset.prevent, v-on:reset.stop, v-on:reset.capture, v-on:reset.self, @reset, @reset.prevent, @reset.stop, @reset.capture, @reset.self, v-on:keydown, v-on:keydown.prevent, v-on:keydown.stop, v-on:keydown.capture, v-on:keydown.self, @keydown, @keydown.prevent, @keydown.stop, @keydown.capture, @keydown.self, v-on:mousenter, v-on:mousenter.prevent, v-on:mousenter.stop, v-on:mousenter.capture, v-on:mousenter.self, v-on:mouseover, v-on:mouseover.prevent, v-on:mouseover.stop, v-on:mouseover.capture, v-on:mouseover.self, v-on:mousemove, v-on:mousemove.prevent, v-on:mousemove.stop, v-on:mousemove.capture, v-on:mousemove.self, v-on:mousedown, v-on:mousedown.prevent, v-on:mousedown.stop, v-on:mousedown.capture, v-on:mousedown.self, v-on:mouseup, v-on:mouseup.prevent, v-on:mouseup.stop, v-on:mouseup.capture, v-on:mouseup.self, @mousenter, @mousenter.prevent, @mousenter.stop, @mousenter.capture, @mousenter.self, @mouseover, @mouseover.prevent, @mouseover.stop, @mouseover.capture, @mouseover.self, @mousemove, @mousemove.prevent, @mousemove.stop, @mousemove.capture, @mousemove.self, @mousedown, @mousedown.prevent, @mousedown.stop, @mousedown.capture, @mousedown.self, @mouseup, @mouseup.prevent, @mouseup.stop, @mouseup.capture, @mouseup.self, v-on:dblclick, v-on:dblclick.prevent, v-on:dblclick.stop, v-on:dblclick.capture, v-on:dblclick.self, v-on:contextmenu, v-on:contextmenu.prevent, v-on:contextmenu.stop, v-on:contextmenu.capture, v-on:contextmenu.self, v-on:wheel, v-on:wheel.prevent, v-on:wheel.stop, v-on:wheel.capture, v-on:wheel.self, v-on:mouseleave, v-on:mouseleave.prevent, v-on:mouseleave.stop, v-on:mouseleave.capture, v-on:mouseleave.self, v-on:mouseout, v-on:mouseout.prevent, v-on:mouseout.stop, v-on:mouseout.capture, v-on:mouseout.self, v-on:select, v-on:select.prevent, v-on:select.stop, v-on:select.capture, v-on:select.self, @dblclick, @dblclick.prevent, @dblclick.stop, @dblclick.capture, @dblclick.self, @contextmenu, @contextmenu.prevent, @contextmenu.stop, @contextmenu.capture, @contextmenu.self, @wheel, @wheel.prevent, @wheel.stop, @wheel.capture, @wheel.self, @mouseleave, @mouseleave.prevent, @mouseleave.stop, @mouseleave.capture, @mouseleave.self, @mouseout, @mouseout.prevent, @mouseout.stop, @mouseout.capture, @mouseout.self, @select, @select.prevent, @select.stop, @select.capture, @select.self, v-bind:key
    

    我会评论你之前的回答,但字符数限制阻止我这样做。

    注意:还有更多可用的events,我只挑选了最常见的,在我自己看来。

    【讨论】:

    • 谢谢,伙计,我已在已接受的答案中添加了指向您答案的链接
    • 注意:我刚刚更新了该列表,因为它在“.self”结束的事件之后错过了一些逗号。
    【解决方案3】:

    我用单独的模板文件来规避模板注入,这不是很好......

    <template lang="pug" src="./MyComponent.pug">
    

    【讨论】:

      【解决方案4】:

      WebStorm 正式开始支持 VueJS See their blog

      但现在它只在 Early Access Preview Build

      中工作

      【讨论】:

        猜你喜欢
        • 2019-10-25
        • 1970-01-01
        • 2018-01-22
        • 1970-01-01
        • 2019-11-30
        • 1970-01-01
        • 2016-02-07
        • 2017-11-11
        • 2018-11-05
        相关资源
        最近更新 更多