Vue.js 3.0 Tutorial

Vue.js 3.0 Component Advanced

Vue.js 3.0 Transitions & Animations

Vue.js 3.0 Reusable & Combinable

Vue.js 3.0 Advanced

Vue.js 3.0 Tools

Vue.js 3.0 Scale

Vue.js 3.0 Accessibility

Vue.js 3.0 Migrating from Vue2

Vue.js 3.0 Contribute Documentation

Vue.js 3.0 API References

Vue.js 3.0 Style Guide

Vue 3.0 Semantics

HTML semantics refers to using the correct HTML elements for their intended purpose. For example, using a <nav> element for navigation, <header> for a header, <footer> for a footer, and so on. This is important because it helps machines (like search engine crawlers and screen readers) understand the content and structure of your webpage.

Here's a basic example of how you can use semantic HTML in a Vue 3.0 component:

<template>
  <section>
    <header>
      <h1>{{ title }}</h1>
    </header>
    <nav>
      <ul>
        <li v-for="(item, index) in menu" :key="index">
          <a :href="item.link">{{ item.text }}</a>
        </li>
      </ul>
    </nav>
    <main>
      <p>{{ content }}</p>
    </main>
    <footer>
      <p>{{ footer }}</p>
    </footer>
  </section>
</template>

<script>
export default {
  data() {
    return {
      title: 'My App',
      menu: [
        { text: 'Home', link: '#' },
        { text: 'About', link: '#' },
        { text: 'Contact', link: '#' },
      ],
      content: 'This is the main content of my app.',
      footer: 'This is the footer of my app.',
    };
  },
};
</script>

In this Vue.js component:

  1. We're using a <section> to group related content together.
  2. The <header> is used to contain the heading of the section.
  3. We use a <nav> element for navigation.
  4. The <main> element is used for the main content of the document.
  5. And finally, we use the <footer> element for the footer.

While Vue.js doesn't specifically enforce semantic HTML, as a developer, it's your responsibility to structure your HTML correctly and semantically. This can be beneficial not only for accessibility and SEO, but also for understanding and maintaining your code.

  1. ARIA Roles and Vue 3.0:

    • Description: Accessible Rich Internet Applications (ARIA) roles help convey information to assistive technologies about the purpose and structure of elements.
    • Code Example:
      <template>
        <button aria-label="Close" @click="closeModal">X</button>
      </template>
      
      <script>
      export default {
        methods: {
          closeModal() {
            // Close modal logic
          },
        },
      };
      </script>
      
  2. Proper Use of HTML Elements in Vue 3.0:

    • Description: Use HTML elements appropriately, choosing elements that convey the correct meaning and semantics.
    • Code Example:
      <template>
        <nav>
          <ul>
            <li><a href="/">Home</a></li>
            <li><a href="/about">About</a></li>
          </ul>
        </nav>
      </template>
      
  3. Vue 3.0 Semantic Component Naming:

    • Description: Choose component names that reflect their purpose and use semantic terms.
    • Code Example:
      <script>
      export default {
        name: 'AccessibleModal',
        // ...
      };
      </script>
      
  4. Vue 3.0 Semantic Attributes and Properties:

    • Description: Leverage HTML semantic attributes and Vue properties to enhance accessibility.
    • Code Example:
      <template>
        <img :src="imageSrc" alt="Vue Logo" aria-describedby="logoDescription">
        <p id="logoDescription">Vue.js Logo</p>
      </template>
      
      <script>
      export default {
        data() {
          return {
            imageSrc: 'vue-logo.png',
          };
        },
      };
      </script>
      
  5. Vue 3.0 HTML5 Semantic Elements:

    • Description: Utilize HTML5 semantic elements like <header>, <nav>, <main>, <article>, <footer>, etc., for improved document structure.
    • Code Example:
      <template>
        <article>
          <header>
            <h1>{{ articleTitle }}</h1>
            <p>Published on: {{ publishDate }}</p>
          </header>
          <main>
            <!-- Article content goes here -->
          </main>
          <footer>
            <p>Author: {{ author }}</p>
          </footer>
        </article>
      </template>
      
      <script>
      export default {
        data() {
          return {
            articleTitle: 'Vue 3.0 Accessibility',
            publishDate: '2023-01-01',
            author: 'Your Name',
          };
        },
      };
      </script>