Home > Web Front-end > JS Tutorial > body text

.vue file generation and usage examples sharing

小云云
Release: 2018-02-08 11:46:29
Original
2765 people have browsed it

In the past few days, new projects have been developed with vue2.0. Since I have never used vue before, when I got the project framework, I saw that they were all .vue files. This article mainly introduces the generation of .vue files in the vue2.0 development introductory notes. and use , very practical value, friends in need can refer to it, I hope it can help everyone.

.vue file generation and usage examples sharing

I don’t know how to use it. Here are my findings about .vue files:

1. A .vue file is an encapsulated component. In the .vue file, you can write html, css, js

.vue file generation and usage examples sharing

Writing html code in template is actually defining the template.

2. The styles of each .vue are not independent. The same selector can work in different .vue as long as it meets the selected conditions. For example, I defined the style in the file pointed by arrow 1. box{ width:200px; }, if there is also .box in the file pointed by arrow 2, then .box{ width:200px; } will also work in the file pointed by arrow 2, unless the style is redefined in the file pointed by arrow 2 and covered.

.vue file generation and usage examples sharing

3. When not using a .vue single file, create a Vue root instance through the Vue constructor to start vuejs. In the .vue file, you do not need to use Vue to create an instance, use export default. The object after export default in the .vue file is equivalent to the accepted object in the new Vue() constructor:

.vue file generation and usage examples sharing

That is:


<script>
  export default{
    data:function(){
      return {
        //返回一个对象
      }
    },
    methods:{
      //定义方法
    }
  }
</script>
Copy after login

4. You can introduce less, etc.:

.vue file generation and usage examples sharing

5. Set the jump path in route.js. If it is transferred to a certain folder index.vue file, you can omit the index.vue after the folder. When you want to jump to this file:

.vue file generation and usage examples sharing

, the following two sentences are equivalent:

.vue file generation and usage examples sharing

.vue file generation and usage examples sharing

So the index.vue after the folder is generally omitted.

Related recommendations:

Detailed explanation of monitoring the input input event oninput in the .vue file

First introduction to Vue.js *.Vue file_vue.js

Webstorm’s new .vue file supports highlighted vue syntax and es6 syntax

The above is the detailed content of .vue file generation and usage examples sharing. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
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!