WebStorm无法识别.vue文件

5

我使用Vue-CLI创建了一个Vue项目,但是当我用WebStorm打开这个项目时,.vue文件看起来像纯文本,没有语法高亮。

enter image description here

以下是代码:

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <h1>{{ msg }}</h1>
    <h2>Essential Links</h2>
    <ul>
      <li><a href="https://vuejs.org" target="_blank">Core Docs</a></li>
      <li><a href="https://forum.vuejs.org" target="_blank">Forum</a></li>
      <li><a href="https://chat.vuejs.org" target="_blank">Community Chat</a></li>
      <li><a href="https://twitter.com/vuejs" target="_blank">Twitter</a></li>
    </ul>
    <h2>Ecosystem</h2>
    <ul>
      <li><a href="http://router.vuejs.org/" target="_blank">vue-router</a></li>
      <li><a href="http://vuex.vuejs.org/" target="_blank">vuex</a></li>
      <li><a href="http://vue-loader.vuejs.org/" target="_blank">vue-loader</a></li>
      <li><a href="https://github.com/vuejs/awesome-vue" target="_blank">awesome-vue</a></li>
    </ul>
  </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

h1, h2 {
  font-weight: normal;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  display: inline-block;
  margin: 0 10px;
}

a {
  color: #42b983;
}
</style>

2个回答

6
请确保在首选项|插件中启用Vue.js插件 - 它已与最新的WebStorm版本捆绑在一起。如果已安装并启用,请确保将*.vue扩展名分配给Vue.js模板,并且您没有在首选项|编辑器|文件类型中为文本文件类型注册App.vue模式。

6

首先,在“Preferences | Plugins”中添加Vue.js插件。

然后,您需要:

进入:WebStorm -> Preferences -> Editor -> File Types -> HTML:

enter image description here

在“Registered Patterns”中没有*.vue

像这样添加*.vue到“Registered Patterns”中:

enter image description here

然后应用它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接