Home  >  Article  >  Web Front-end  >  What does each single file component in vue consist of?

What does each single file component in vue consist of?

下次还敢
下次还敢Original
2024-04-28 00:09:161087browse

Vue single file component consists of three parts: Template: defines the visual representation, using HTML syntax. Script: Define logical behavior, using JavaScript syntax. Style: Define styles, using CSS syntax.

What does each single file component in vue consist of?

The composition of Vue single file component

Vue single file component consists of three parts:

1. Template

The template part defines the visual representation of the component. It is written using HTML syntax and can dynamically render data using Vue directives and interpolation.

2. Script

The script part defines the logical behavior of the component. It is written in JavaScript and contains the component's data, methods, and lifecycle hooks.

3. Style

The style part defines the style of the component. It can be written using CSS syntax and can contain class selectors, ID selectors, and media queries.

Example:

<code class="html"><template>
  <div>
    <h1>{{ title }}</h1>
    <p>{{ message }}</p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title: 'Hello Vue',
      message: 'Welcome to the Vue world!'
    }
  }
}
</script>

<style>
h1 {
  color: blue;
}
p {
  color: red;
}
</style></code>

In this example:

  • The template section defines a template with the title and The div container for the message.
  • The script section defines the component's title and message data.
  • The style section defines the style attributes of the h1 and p elements.

The above is the detailed content of What does each single file component in vue consist of?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:The role of router in vueNext article:The role of router in vue