WebStorm无法识别.vue文件

时间:2018-02-03 01:03:27

标签: webstorm

我使用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 个答案:

答案 0 :(得分:3)

Make sure that Vue.js plugin is enabled in Preferences | Plugins - it is bundled with recent WebStorm versions. If it's installed and enabled, make sure that *.vue extension is assigned to Vue.js Templates in Preferences | Editor | File Types, and that your don't have App.vue pattern registered for Text file type there

答案 1 :(得分:1)

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

然后你应该

转到:WebStorm - &gt;偏好 - &gt;编辑 - &gt;文件类型 - &gt; HTML:

enter image description here

Registered Patterns中的

没有*.vue

*.vue中添加Registered Patterns,如下所示:

enter image description here

然后应用它。

相关问题