javascript - Can vue not have the .vue suffix? I want to introduce it into old projects, what should I do?
迷茫
迷茫 2017-05-19 10:35:12
0
5
830

Can vue not have the .vue suffix? I want to introduce it into an old project. What should I do?

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(5)
大家讲道理

Old projects directly import vue.js files

<script src="https://unpkg.com/vue/dist/vue.js"></script>
为情所困

You can try html. But this does not conform to the syntax of vue, it will report an error

为情所困

.vue format is not the file that is ultimately introduced into the page. After being packaged by webpack, a normal js file will be generated. Just introduce this js file.

淡淡烟草味

Deploy the old project to v-cli, then reference the .vue component, and then package it with webpack

阿神

The first question is about the suffix.
The suffix has nothing to do with VUE. Vue is just a special text file, even if you use .abc.
This is all thanks to webpack. In the loaders configuration of webpack, you can give one or more loaders to the specified file. You can also think of these loaders as precompilation tools.

  module: {
    rules: [{
        test: /\.vue$/, // 这里指定 .vue 文件通过 vue-loader 解析,你可以指定任何类型的文件。
        loader: 'vue-loader',
        options: vueLoaderConfig
      }]
   }

Second question, vue small project is similar to the usage of third-party libraries

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>vue-demo</title>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
  </head>
  <body>
    <p id="app">
      {{ message }}
    </p>
  </body>

  <script>
    var app = new Vue({
      el: '#app',
      data: {
        message: 'Hello Vue!'
      }
    })
  </script>
</html>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!