Link Component
Learning Objectives
- Master the basic usage of the Link component
- Understand different types and states of links
- Learn to use icon links and underline control
- Master link style customization and interaction design
- Be able to create aesthetically pleasing and functional link interfaces
Detailed Learning Content
1. Link Component Basics (30 minutes)
1.1 Basic Links
The Link component is used to create clickable links, supporting various types and styles.
<template>
<div class="link-demo">
<!-- Basic link -->
<el-link href="https://element-plus.org" target="_blank">
Default Link
</el-link>
<!-- Different types of links -->
<el-link type="primary">Primary Link</el-link>
<el-link type="success">Success Link</el-link>
<el-link type="info">Info Link</el-link>
<el-link type="warning">Warning Link</el-link>
<el-link type="danger">Danger Link</el-link>
</div>
</template>
<style>
.link-demo {
display: flex;
flex-direction: column;
gap: 10px;
}
</style>
1.2 Disabled State
<template>
<div class="link-disabled-demo">
<el-link disabled>Disabled Link</el-link>
<el-link type="primary" disabled>Disabled Primary Link</el-link>
<el-link type="success" disabled>Disabled Success Link</el-link>
</div>
</template>
1.3 Underline Control
<template>
<div class="link-underline-demo">
<el-link :underline="false">No Underline</el-link>
<el-link>Default Underline</el-link>
<el-link :underline="true">Forced Underline</el-link>
</div>
</template>
1.4 Icon Links
<template>
<div class="link-icon-demo">
<el-link :icon="Edit">Edit Link</el-link>
<el-link :icon="View">View Link</el-link>
<el-link :icon="Delete" type="danger">Delete Link</el-link>
<!-- Icon on the right -->
<el-link>
Download File
<el-icon class="el-icon--right"><Download /></el-icon>
</el-link>
</div>
</template>
<script setup>
import { Edit, View, Delete, Download } from '@element-plus/icons-vue'
</script>
2. Advanced Link Applications (40 minutes)
2.1 Link Size Control
<template>
<div class="link-size-demo">
<h3>Link Sizes</h3>
<div class="size-group">
<el-link size="large" type="primary">Large Link</el-link>
<el-link type="primary">Default Link</el-link>
<el-link size="small" type="primary">Small Link</el-link>
</div>
<!-- Custom sizes -->
<div class="custom-size-group">
<el-link class="extra-large" type="success">Extra Large Link</el-link>
<el-link class="mini" type="info">Mini Link</el-link>
</div>
</div>
</template>
<style>
.link-size-demo {
margin-bottom: 24px;
}
.size-group,
.custom-size-group {
display: flex;
align-items: center;
gap: 16px;
margin-bottom: 16px;
}
.extra-large {
font-size: 20px;
font-weight: 600;
}
.mini {
font-size: 12px;
}
</style>
2.2 Link State Styles
<template>
<div class="link-state-demo">
<h3>Link State Styles</h3>
<!-- Hover effects -->
<div class="hover-effects">
<el-link class="hover-scale" type="primary">Hover Scale</el-link>
<el-link class="hover-glow" type="success">Hover Glow</el-link>
<el-link class="hover-slide" type="warning">Hover Slide</el-link>
</div>
<!-- Active states -->
<div class="active-states">
<el-link class="active-pressed" type="danger">Click Effect</el-link>
<el-link class="active-bounce" type="info">Bounce Effect</el-link>
</div>
</div>
</template>
<style>
.link-state-demo {
margin-bottom: 24px;
}
.hover-effects,
.active-states {
display: flex;
gap: 20px;
margin-bottom: 16px;
}
.hover-scale {
transition: transform 0.2s ease;
}
.hover-scale:hover {
transform: scale(1.1);
}
.hover-glow {
transition: box-shadow 0.3s ease;
}
.hover-glow:hover {
box-shadow: 0 0 10px rgba(103, 194, 58, 0.5);
}
.hover-slide {
position: relative;
overflow: hidden;
transition: color 0.3s ease;
}
.hover-slide::before {
content: '';
position: absolute;
top: 0;
left: -100%;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(230, 162, 60, 0.2), transparent);
transition: left 0.5s ease;
}
.hover-slide:hover::before {
left: 100%;
}
.active-pressed:active {
transform: scale(0.95);
transition: transform 0.1s ease;
}
.active-bounce:active {
animation: bounce 0.3s ease;
}
@keyframes bounce {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-3px); }
}
</style>
2.3 Link Combination Applications
<template>
<div class="link-combination-demo">
<h3>Link Combination Applications</h3>
<!-- Navigation link group -->
<nav class="nav-links">
<el-link type="primary" :underline="false">Home</el-link>
<el-link type="primary" :underline="false">Products</el-link>
<el-link type="primary" :underline="false">Services</el-link>
<el-link type="primary" :underline="false">About Us</el-link>
<el-link type="primary" :underline="false">Contact Us</el-link>
</nav>
<!-- Action link group -->
<div class="action-links">
<el-link :icon="Edit" type="primary">Edit</el-link>
<el-link :icon="View" type="info">View</el-link>
<el-link :icon="Share" type="success">Share</el-link>
<el-link :icon="Delete" type="danger">Delete</el-link>
</div>
<!-- Social link group -->
<div class="social-links">
<el-link class="social-link github" :underline="false">
<el-icon><Github /></el-icon>
GitHub
</el-link>
<el-link class="social-link twitter" :underline="false">
<el-icon><Twitter /></el-icon>
Twitter
</el-link>
<el-link class="social-link linkedin" :underline="false">
<el-icon><Linkedin /></el-icon>
LinkedIn
</el-link>
</div>
</div>
</template>
<script setup>
import {
Edit, View, Share, Delete,
Github, Twitter, Linkedin
} from '@element-plus/icons-vue'
</script>
<style>
.link-combination-demo {
margin-bottom: 24px;
}
.nav-links {
display: flex;
gap: 24px;
margin-bottom: 20px;
padding: 12px 0;
border-bottom: 1px solid #e4e7ed;
}
.action-links {
display: flex;
gap: 16px;
margin-bottom: 20px;
}
.social-links {
display: flex;
gap: 16px;
}
.social-link {
display: flex;
align-items: center;
gap: 6px;
padding: 8px 12px;
border-radius: 6px;
transition: all 0.3s ease;
}
.social-link.github {
color: #333;
background-color: #f6f8fa;
}
.social-link.github:hover {
background-color: #333;
color: white;
}
.social-link.twitter {
color: #1da1f2;
background-color: #e8f4fd;
}
.social-link.twitter:hover {
background-color: #1da1f2;
color: white;
}
.social-link.linkedin {
color: #0077b5;
background-color: #e8f3f8;
}
.social-link.linkedin:hover {
background-color: #0077b5;
color: white;
}
</style>
3. Accessible Link Design (20 minutes)
3.1 Accessibility Attributes
<template>
<div class="accessibility-demo">
<h3>Accessible Link Design</h3>
<!-- Descriptive link text -->
<div class="descriptive-links">
<p>
To learn more about our products, please
<el-link
href="/products"
aria-label="View product details page"
type="primary"
>
click here
</el-link>
</p>
<p>
Download our latest report
<el-link
href="/report.pdf"
target="_blank"
aria-label="Download annual report in PDF format (opens in new window)"
type="success"
>
Annual Report (PDF)
<el-icon class="el-icon--right"><Download /></el-icon>
</el-link>
</p>
</div>
<!-- Keyboard navigation support -->
<div class="keyboard-navigation">
<h4>Keyboard Navigation Example</h4>
<div class="nav-group" role="navigation" aria-label="Main Navigation">
<el-link
tabindex="0"
@keydown.enter="handleNavigation('home')"
@keydown.space.prevent="handleNavigation('home')"
type="primary"
>
Home
</el-link>
<el-link
tabindex="0"
@keydown.enter="handleNavigation('about')"
@keydown.space.prevent="handleNavigation('about')"
type="primary"
>
About
</el-link>
<el-link
tabindex="0"
@keydown.enter="handleNavigation('contact')"
@keydown.space.prevent="handleNavigation('contact')"
type="primary"
>
Contact
</el-link>
</div>
</div>
<!-- Focus indicators -->
<div class="focus-indicators">
<h4>Focus Indicators</h4>
<el-link class="focus-visible" type="primary">Visible Focus Link</el-link>
<el-link class="focus-enhanced" type="success">Enhanced Focus Link</el-link>
</div>
</div>
</template>
<script setup>
import { Download } from '@element-plus/icons-vue'
const handleNavigation = (page) => {
console.log(`Navigate to: ${page}`)
// Actual navigation logic
}
</script>
<style>
.accessibility-demo {
margin-bottom: 24px;
}
.descriptive-links,
.keyboard-navigation,
.focus-indicators {
margin-bottom: 20px;
}
.nav-group {
display: flex;
gap: 16px;
}
.focus-visible:focus {
outline: 2px solid #409eff;
outline-offset: 2px;
border-radius: 4px;
}
.focus-enhanced:focus {
outline: 3px solid #67c23a;
outline-offset: 3px;
border-radius: 6px;
box-shadow: 0 0 0 1px white, 0 0 0 4px #67c23a;
}
</style>
4. Comprehensive Application Example (30 minutes)
4.1 Article Link System
<template>
<div class="article-link-system">
<article class="article">
<header class="article-header">
<h1>Complete Guide to Element Plus Link Component</h1>
<div class="article-meta">
<span>Author:</span>
<el-link type="primary" :underline="false">John Doe</el-link>
<span>Published: January 1, 2024</span>
</div>
</header>
<main class="article-content">
<p>
Element Plus's
<el-link
href="https://element-plus.org/en-US/component/link.html"
target="_blank"
type="primary"
>
Link component
</el-link>
provides rich link styles and functionality.
</p>
<h2>Related Resources</h2>
<ul class="resource-list">
<li>
<el-link :icon="Document" type="info">
Official Documentation
</el-link>
</li>
<li>
<el-link :icon="VideoPlay" type="success">
Video Tutorial
</el-link>
</li>
<li>
<el-link :icon="Download" type="warning">
Sample Code
</el-link>
</li>
</ul>
<h2>External Links</h2>
<div class="external-links">
<el-link
href="https://github.com/element-plus/element-plus"
target="_blank"
class="external-link"
>
GitHub Repository
<el-icon class="el-icon--right"><Link /></el-icon>
</el-link>
<el-link
href="https://discord.gg/gXK9XNzW3X"
target="_blank"
class="external-link"
>
Discord Community
<el-icon class="el-icon--right"><Link /></el-icon>
</el-link>
</div>
</main>
<footer class="article-footer">
<div class="article-actions">
<el-link :icon="Share" type="primary">Share Article</el-link>
<el-link :icon="Star" type="warning">Bookmark</el-link>
<el-link :icon="ChatDotRound" type="info">Comment</el-link>
</div>
<div class="article-navigation">
<el-link :icon="ArrowLeft" type="info">Previous Article</el-link>
<el-link type="info">
Next Article
<el-icon class="el-icon--right"><ArrowRight /></el-icon>
</el-link>
</div>
</footer>
</article>
</div>
</template>
<script setup>
import {
Document, VideoPlay, Download, Link, Share, Star,
ChatDotRound, ArrowLeft, ArrowRight
} from '@element-plus/icons-vue'
</script>
<style>
.article-link-system {
max-width: 800px;
margin: 0 auto;
}
.article {
background: white;
border-radius: 8px;
padding: 32px;
box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}
.article-header {
margin-bottom: 32px;
padding-bottom: 16px;
border-bottom: 1px solid #e4e7ed;
}
.article-meta {
display: flex;
align-items: center;
gap: 8px;
margin-top: 12px;
color: #909399;
font-size: 14px;
}
.article-content {
line-height: 1.8;
margin-bottom: 32px;
}
.resource-list {
list-style: none;
padding: 0;
margin: 16px 0;
}
.resource-list li {
margin-bottom: 8px;
}
.external-links {
display: flex;
gap: 16px;
margin: 16px 0;
}
.external-link {
display: flex;
align-items: center;
gap: 4px;
}
.article-footer {
padding-top: 24px;
border-top: 1px solid #e4e7ed;
}
.article-actions {
display: flex;
gap: 16px;
margin-bottom: 16px;
}
.article-navigation {
display: flex;
justify-content: space-between;
}
</style>
Practice Exercises
Exercise 1: Basic Link Display
Create a page displaying all types of Link components and states.
Exercise 2: Navigation Link System
Implement a website navigation bar, including main navigation and breadcrumb navigation.
Exercise 3: Social Media Links
Create a social media link component that supports multiple platforms.
Exercise 4: Accessible Link Component
Implement a link component that fully complies with accessibility standards.
Design Principles
- Identifiability: Links should be clearly distinguishable from regular text
- Consistency: Maintain consistency in link styles throughout the application
- Accessibility: Ensure links are accessible to all users
- Semantics: Use meaningful link text
- Feedback: Provide clear interaction feedback
Learning Resources
- Link Component Official Documentation
- Web Link Design Best Practices
- Accessible Link Design Guide
- CSS Link Styling Techniques
Assignments
- Basic Assignment: Create a display page containing all link types
- Advanced Assignment: Implement a complete website navigation system
- Challenge Assignment: Design a link component library that supports theme switching
Summary
The Link component is an important element of web interaction. By properly using different types of links, combined with good design principles and accessibility standards, you can create link interfaces that are both aesthetically pleasing and functional. Mastering the use of link components is important for improving user experience and website usability.
Learning Date: ___________ Completion Status: ___________ Learning Notes:
Problems Encountered:
Solutions: