前言:哈嘍,大家好,今天給大家分享一篇文章!并提供具體代碼幫助大家深入理解,徹底掌握!創作不易,如果能幫助到大家或者給大家一些靈感和啟發,歡迎收藏+關注哦 💕
目錄
- DeepSeek 助力 Vue 開發:打造絲滑的單選按鈕(Radio Button)
- 📚前言
- 📚頁面效果
- 📚指令輸入
- 定義屬性
- 1. 基礎屬性
- 2. 狀態屬性
- 3. 樣式屬性
- 4. 分組屬性
- 定義事件
- 1. 選中事件
- 2. 點擊事件
- 其他
- 1. 兼容性
- 2. 可訪問性
- 3. 樣式定制
- 4. 錯誤處理
- 5. 文檔和示例
- 📚think
- 📘組件代碼
- 📚代碼測試
- 📚測試代碼正常跑通,附其他基本代碼
- 📘編寫路由 src\router\index.js
- 📘編寫展示入口 src\App.vue
- 📚頁面效果
- 📚相關文章
📚📗📕📘📖🕮💡📝🗂???🛠?💻🚀🎉🏗?🌐🖼?🔗📊👉🔖??🌟🔐??·正文開始
??·🎥😊🎓📩😺🌈🤝🤖📜📋🔍?🧰?📄📢📈 🙋0??1??2??3??4??5??6??7??8??9??🔟🆗*??#??
DeepSeek 助力 Vue 開發:打造絲滑的單選按鈕(Radio Button)
📚前言
在全球 AI 市場,DeepSeek 憑借其創新的技術和獨特的優勢,迅速贏得了市場份額,打破了原有的市場格局。許多企業開始重新評估自身的 AI 戰略,加大對 AI 技術的研發投入,以應對 DeepSeek 帶來的競爭壓力。同時,DeepSeek 的開源策略也促進了全球 AI 社區的發展,吸引了更多的開發者和企業參與到 AI 技術的創新和應用中,推動了全球 AI 市場的繁榮。
在大語言模型的發展浪潮中,DeepSeek 雖取得了顯著成就,但也面臨著諸多技術挑戰。
算力需求是首要難題。隨著模型規模的不斷擴大,對算力的要求呈指數級增長。以 DeepSeek-V3 為例,其總參數達 6710 億,如此龐大的模型在訓練過程中需要消耗大量的計算資源。訓練這樣的大模型需要強大的計算集群支持,而構建和維護這樣的計算集群不僅成本高昂,還面臨著技術難題。算力瓶頸不僅限制了模型的訓練速度和效率,也增加了研發成本和時間。在實際訓練中,由于算力不足,可能會導致訓練時間延長,無法及時迭代模型,從而影響產品的競爭力。
📚頁面效果
📚指令輸入
已經創建好了一個基于Vue3的組合式API的項目(Composition API),并能正常運行起來,請幫我用 Vue3的組合式API(Composition API) 生成一個 單選按鈕(Radio Button) 的功能組件,所有代碼都保存在components/RadioButton 下的文件夾中。功能組件的script標簽中只有setup屬性,使用普通 JavaScript 實現,不使用TypeScript。
功能要有,如下屬性:
定義屬性
1. 基礎屬性
value
:用于綁定單選按鈕的值,當單選按鈕被選中時,該值會被傳遞出去。通常與父組件中的v-model
配合使用,實現雙向數據綁定。label
:顯示在單選按鈕旁邊的文本標簽,用于提示用戶該單選按鈕的含義。
2. 狀態屬性
checked
:用于控制單選按鈕是否被選中。可以是布爾值,也可以與某個值進行比較來確定是否選中。disabled
:布爾類型,用于禁用單選按鈕,使其不可點擊。
3. 樣式屬性
size
:用于設置單選按鈕的大小,例如small
、medium
、large
等,方便統一調整組件的外觀。color
:設置單選按鈕的顏色,以滿足不同的設計需求。
4. 分組屬性
name
:用于將多個單選按鈕歸為一組,同一組內的單選按鈕只能有一個被選中。類似于原生 HTML 中input[type="radio"]
的name
屬性。
定義事件
1. 選中事件
change
:當單選按鈕的選中狀態發生改變時觸發,通常會傳遞當前選中的值給父組件,方便父組件進行相應的處理。
2. 點擊事件
click
:當用戶點擊單選按鈕時觸發,可用于一些額外的交互邏輯,如統計點擊次數等。
其他
1. 兼容性
- 確保組件在不同瀏覽器和設備上有良好的兼容性,特別是在處理焦點、鍵盤導航等方面。
2. 可訪問性
- 遵循可訪問性標準,為單選按鈕添加適當的
aria-label
或aria-labelledby
屬性,方便屏幕閱讀器等輔助設備識別。
3. 樣式定制
- 提供一些 CSS 類名或插槽,方便用戶自定義單選按鈕的樣式,以適應不同的設計風格。
4. 錯誤處理
- 在組件內部對傳入的屬性進行驗證,當傳入無效屬性時給出明確的錯誤提示,方便開發者調試。
5. 文檔和示例
- 編寫詳細的文檔,說明組件的使用方法、屬性和事件的含義,并提供一些示例代碼,幫助其他開發者快速上手。
你有更好的建議也可以添加,要注明。組件定義好后給出5個及以上的調用示例。
下面是現有目錄
vueAndDeepseek/
├── src/ # 源代碼目錄
│ ├── assets/ # 靜態資源
│ │ ├── base.css
│ │ ├── main.css
│ │ └── logo.svg
│ ├── components/ # 組件目錄
│ │ ├── HelloWorld.vue
│ │ ├── TheWelcome.vue
│ │ ├── WelcomeItem.vue
│ │ ├── Progress/
│ │ │ └── Progress.vue
│ │ ├── Accordion/
│ │ ├── BackToTop/
│ │ ├── Card/
│ │ ├── InfiniteScroll/
│ │ ├── Notification/
│ │ ├── Timeline/
│ │ ├── Switch/
│ │ ├── Tabs/
│ │ ├── Sidebar/
│ │ ├── Breadcrumbs/
│ │ ├── MasonryLayout/
│ │ ├── Rating/
│ │ ├── ColorPicker/
│ │ ├── RightClickMenu/
│ │ ├── RangePicker/
│ │ ├── Navbar/
│ │ ├── FormValidation/
│ │ ├── CopyToClipboard/
│ │ ├── ClickAnimations/
│ │ ├── ThumbnailList/
│ │ ├── KeyboardShortcuts/
│ │ ├── CommentSystem/
│ │ ├── QRCode/
│ │ ├── RadioButton/
│ │ ├── DatePicker/
│ │ └── icons/
│ ├── router/ # 路由配置
│ │ └── index.js
│ ├── stores/ # Pinia 狀態管理
│ │ └── counter.js
│ ├── views/ # 頁面組件
│ │ ├── ProgressView.vue
│ │ ├── TabsView.vue
│ │ ├── SwitchView.vue
│ │ ├── TimelineView.vue
│ │ ├── NotificationView.vue
│ │ ├── CardView.vue
│ │ ├── InfiniteScrollView.vue
│ │ ├── BackToTopView.vue
│ │ ├── AccordionView.vue
│ │ ├── SidebarView.vue
│ │ ├── BreadcrumbsView.vue
│ │ ├── MasonryLayoutView.vue
│ │ ├── RatingView.vue
│ │ ├── ColorPickerView.vue
│ │ ├── RightClickMenuView.vue
│ │ ├── RangePickerView.vue
│ │ ├── NavbarView.vue
│ │ ├── FormValidationView.vue
│ │ ├── CopyToClipboardView.vue
│ │ ├── ClickAnimationsView.vue
│ │ ├── ThumbnailListView.vue
│ │ ├── KeyboardShortcutsView.vue
│ │ ├── CommentSystemView.vue
│ │ ├── QRCodeView.vue
│ │ ├── RadioButtonView.vue
│ │ ├── DatePickerView.vue
│ │ └── AboutView.vue
│ ├── App.vue # 根組件
│ └── main.js # 應用入口
├── public/ # 公共資源目錄
├── index.html # HTML 模板
├── package.json # 項目配置
├── vite.config.js # Vite 配置
└── node_modules/ # 依賴包目錄
📚think
📘組件代碼
根據你的需求,我幫你創建了 RadioButton 組件,以下是具體實現:
components/RadioButton/RadioButton.vue
<template><label class="radio-container":class="[`radio--${size}`,{ 'is-disabled': disabled }]"><inputtype="radio"class="radio-input":checked="isChecked":disabled="disabled":value="value":name="name"@change="handleChange"@click="handleClick":aria-label="ariaLabel"><span class="radio-checkmark":style="checkmarkStyle"></span><span class="radio-label">{{ label }}</span></label>
</template><script setup>
import { computed } from 'vue';const props = defineProps({modelValue: { type: [String, Number, Boolean], required: true },value: { type: [String, Number, Boolean], required: true },label: { type: String, default: '' },checked: { type: Boolean, default: false },disabled: { type: Boolean, default: false },size: { type: String, default: 'medium',validator: (v) => ['small', 'medium', 'large'].includes(v) },color: { type: String, default: '#3b82f6' },name: { type: String, default: '' },ariaLabel: { type: String, default: '' }
});const emit = defineEmits(['update:modelValue', 'change', 'click']);const isChecked = computed(() => props.modelValue !== undefined ? props.modelValue === props.value : props.checked
);const checkmarkStyle = computed(() => ({borderColor: props.color,backgroundColor: isChecked.value ? props.color : 'transparent'
}));const handleChange = (e) => {if (props.disabled) return;emit('update:modelValue', props.value);emit('change', props.value);
};const handleClick = (e) => {if (props.disabled) return;emit('click', e);
};
</script><style scoped>
.radio-container {display: inline-flex;align-items: center;cursor: pointer;user-select: none;margin-right: 16px;
}.radio-input {position: absolute;opacity: 0;height: 0;width: 0;
}.radio-checkmark {position: relative;display: inline-block;width: 18px;height: 18px;border: 2px solid #ccc;border-radius: 50%;margin-right: 8px;transition: all 0.2s ease;
}.radio-checkmark::after {content: "";position: absolute;display: none;top: 3px;left: 3px;width: 8px;height: 8px;border-radius: 50%;background: white;
}.radio-input:checked ~ .radio-checkmark::after {display: block;
}.radio-input:focus-visible ~ .radio-checkmark {box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
}/* 尺寸 */
.radio--small .radio-checkmark {width: 16px;height: 16px;
}
.radio--small .radio-checkmark::after {width: 6px;height: 6px;
}.radio--large .radio-checkmark {width: 20px;height: 20px;
}
.radio--large .radio-checkmark::after {width: 10px;height: 10px;
}/* 禁用狀態 */
.is-disabled {opacity: 0.6;cursor: not-allowed;
}
</style>
以下是5個使用示例:
- 基礎用法
<template><div><RadioButton v-model="selected" value="apple" label="蘋果" /><RadioButtonv-model="selected"value="banana"label="香蕉"/></div>
</template><script setup>
import { ref } from 'vue';
import RadioButton from '@/components/RadioButton/RadioButton.vue';const selected = ref('apple');
</script>
- 禁用狀態
<RadioButtonv-model="selected"value="disabled"label="禁用選項"disabled
/>
- 自定義顏色和尺寸
<RadioButtonv-model="selected"value="custom"label="自定義樣式"color="#ff4757"size="large"
/>
- 分組使用
<template><div><h3>選擇性別</h3><RadioButtonv-model="gender"value="male"label="男"name="gender"/><RadioButtonv-model="gender"value="female"label="女"name="gender"/></div>
</template><script setup>
import { ref } from 'vue';const gender = ref('male');
</script>
- 事件處理
<template><RadioButtonv-model="selected"value="event"label="帶事件選項"@change="handleChange"@click="handleClick"/>
</template><script setup>
const handleChange = (value) => {console.log('選中值變化:', value);
};const handleClick = (event) => {console.log('點擊事件:', event);
};
</script>
額外建議:
- 鍵盤導航支持:已通過原生 input 實現,支持 Space 鍵切換
- 焦點樣式:使用 :focus-visible 偽類實現了可見焦點環
- 過渡動畫:為 checkmark 添加了過渡動畫提升體驗
- 顏色對比度:自動生成的內圈白色確保與自定義顏色形成足夠對比
- 響應式設計:使用 em 單位保證在不同字號下的顯示一致性
組件特性:
- 支持完全鍵盤操作
- 自動處理 ARIA 屬性
- 支持按需樣式覆蓋
- 內置基礎尺寸規范
- 通過原生 input 實現最佳兼容性
- 自動處理瀏覽器默認樣式覆蓋
📚代碼測試
正常
📚測試代碼正常跑通,附其他基本代碼
- 添加路由
- 頁面展示入口
📘編寫路由 src\router\index.js
import { createRouter, createWebHistory } from 'vue-router'
import RightClickMenuView from '../views/RightClickMenuView.vue'
import RangePickerView from '../views/RangePickerView.vue'const router = createRouter({history: createWebHistory(import.meta.env.BASE_URL),routes: [{path: '/',name: 'progress',component: () => import('../views/ProgressView.vue'),},{path: '/tabs',name: 'tabs',// route level code-splitting// this generates a separate chunk (About.[hash].js) for this route// which is lazy-loaded when the route is visited.// 標簽頁(Tabs)component: () => import('../views/TabsView.vue'),},{path: '/accordion',name: 'accordion',// 折疊面板(Accordion)component: () => import('../views/AccordionView.vue'),},{path: '/timeline',name: 'timeline',// 時間線(Timeline)component: () => import('../views/TimelineView.vue'),},{path: '/backToTop',name: 'backToTop',component: () => import('../views/BackToTopView.vue')},{path: '/notification',name: 'notification',component: () => import('../views/NotificationView.vue')},{path: '/card',name: 'card',component: () => import('../views/CardView.vue')},{path: '/infiniteScroll',name: 'infiniteScroll',component: () => import('../views/InfiniteScrollView.vue')},{path: '/switch',name: 'switch',component: () => import('../views/SwitchView.vue')},{path: '/sidebar',name: 'sidebar',component: () => import('../views/SidebarView.vue')},{path: '/breadcrumbs',name: 'breadcrumbs',component: () => import('../views/BreadcrumbsView.vue')},{path: '/masonryLayout',name: 'masonryLayout',component: () => import('../views/MasonryLayoutView.vue')},{path: '/rating',name: 'rating',component: () => import('../views/RatingView.vue')},{path: '/datePicker',name: 'datePicker',component: () => import('../views/DatePickerView.vue')},{path: '/colorPicker',name: 'colorPicker',component: () => import('../views/ColorPickerView.vue')},{path: '/rightClickMenu',name: 'rightClickMenu',component: RightClickMenuView},{path: '/rangePicker',name: 'rangePicker',component: () => import('../views/RangePickerView.vue')},{path: '/navbar',name: 'navbar',component: () => import('../views/NavbarView.vue')},{path: '/formValidation',name: 'formValidation',component: () => import('../views/FormValidationView.vue')},{path: '/copyToClipboard',name: 'copyToClipboard',component: () => import('../views/CopyToClipboardView.vue')},{path: '/clickAnimations',name: 'clickAnimations',component: () => import('../views/ClickAnimationsView.vue')},{path: '/thumbnailList',name: 'thumbnailList',component: () => import('../views/ThumbnailListView.vue')},{path: '/keyboardShortcuts',name: 'keyboardShortcuts',component: () => import('../views/KeyboardShortcutsView.vue')},{path: '/commentSystem',name: 'commentSystem',component: () => import('../views/CommentSystemView.vue')},{path: '/qRCode',name: 'qRCode',component: () => import('../views/QRCodeView.vue')},{path: '/radioButton',name: 'radioButton',component: () => import('../views/RadioButtonView.vue')}],
})export default router
📘編寫展示入口 src\App.vue
<script setup>
import { RouterLink, RouterView } from 'vue-router'
import HelloWorld from './components/HelloWorld.vue'
</script><template><header><img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" /><div class="wrapper"><HelloWorld msg="You did it!" /><nav><RouterLink to="/">Progress</RouterLink><RouterLink to="/tabs">Tabs</RouterLink><RouterLink to="/accordion">Accordion</RouterLink><RouterLink to="/timeline">Timeline</RouterLink><RouterLink to="/backToTop">BackToTop</RouterLink><RouterLink to="/notification">Notification</RouterLink><RouterLink to="/card">Card</RouterLink><RouterLink to="/infiniteScroll">InfiniteScroll</RouterLink><RouterLink to="/switch">Switch</RouterLink><RouterLink to="/sidebar">Sidebar</RouterLink><RouterLink to="/breadcrumbs">Breadcrumbs</RouterLink><RouterLink to="/masonryLayout">MasonryLayout</RouterLink><RouterLink to="/rating">Rating</RouterLink><RouterLink to="/datePicker">DatePicker</RouterLink><RouterLink to="/colorPicker">ColorPicker</RouterLink><RouterLink to="/rightClickMenu">RightClickMenu</RouterLink><RouterLink to="/rangePicker">RangePicker</RouterLink><RouterLink to="/navbar">Navbar</RouterLink><RouterLink to="/formValidation">FormValidation</RouterLink><RouterLink to="/copyToClipboard">CopyToClipboard</RouterLink><RouterLink to="/clickAnimations">ClickAnimations</RouterLink><RouterLink to="/thumbnailList">ThumbnailList</RouterLink><RouterLink to="/keyboardShortcuts">KeyboardShortcuts</RouterLink><RouterLink to="/commentSystem">CommentSystem</RouterLink><RouterLink to="/qRCode">QRCode</RouterLink><RouterLink to="/radioButton">RadioButton</RouterLink></nav></div></header><RouterView />
</template><style scoped>
header {line-height: 1.5;max-height: 100vh;
}.logo {display: block;margin: 0 auto 2rem;
}nav {width: 100%;font-size: 12px;text-align: center;margin-top: 2rem;
}nav a.router-link-exact-active {color: var(--color-text);
}nav a.router-link-exact-active:hover {background-color: transparent;
}nav a {display: inline-block;padding: 0 1rem;border-left: 1px solid var(--color-border);
}nav a:first-of-type {border: 0;
}@media (min-width: 1024px) {header {display: flex;place-items: center;padding-right: calc(var(--section-gap) / 2);}.logo {margin: 0 2rem 0 0;}header .wrapper {display: flex;place-items: flex-start;flex-wrap: wrap;}nav {text-align: left;margin-left: -1rem;font-size: 1rem;padding: 1rem 0;margin-top: 1rem;}
}
</style>
📚頁面效果
📚相關文章
?
?
-
0基礎3步部署自己的DeepSeek安裝步驟
-
DeepSeek 助力 Vue 開發:打造絲滑的步驟條(Step bar)https://blog.csdn.net/qq_33650655/article/details/145560497
-
DeepSeek 助力 Vue 開發:打造絲滑的進度條(Progress Bar)https://blog.csdn.net/qq_33650655/article/details/145577034
-
自己部署 DeepSeek 助力 Vue 開發:打造絲滑的標簽頁(Tabs)https://blog.csdn.net/qq_33650655/article/details/145587999
-
自己部署 DeepSeek 助力 Vue 開發:打造絲滑的折疊面板(Accordion)https://blog.csdn.net/qq_33650655/article/details/145590404
-
自己部署 DeepSeek 助力 Vue 開發:打造絲滑的時間線(Timeline )https://blog.csdn.net/qq_33650655/article/details/145597372
-
DeepSeek 助力 Vue 開發:打造絲滑的返回頂部按鈕(Back to Top)https://blog.csdn.net/qq_33650655/article/details/145615550
-
DeepSeek 助力 Vue 開發:打造絲滑的通知欄(Notification Bar)https://blog.csdn.net/qq_33650655/article/details/145620055
-
DeepSeek 助力 Vue 開發:打造絲滑的卡片(Card)https://blog.csdn.net/qq_33650655/article/details/145634564
-
DeepSeek 助力 Vue 開發:打造絲滑的無限滾動(Infinite Scroll)https://blog.csdn.net/qq_33650655/article/details/145638452
-
DeepSeek 助力 Vue 開發:打造絲滑的開關切換(Switch)https://blog.csdn.net/qq_33650655/article/details/145644151
-
DeepSeek 助力 Vue 開發:打造絲滑的側邊欄(Sidebar)https://blog.csdn.net/qq_33650655/article/details/145654204
-
DeepSeek 助力 Vue 開發:打造絲滑的面包屑導航(Breadcrumbs)https://blog.csdn.net/qq_33650655/article/details/145656895
-
DeepSeek 助力 Vue 開發:打造絲滑的瀑布流布局(Masonry Layout)https://blog.csdn.net/qq_33650655/article/details/145663699
-
DeepSeek 助力 Vue 開發:打造絲滑的評分組件(Rating)https://blog.csdn.net/qq_33650655/article/details/145664576
-
DeepSeek 助力 Vue 開發:打造絲滑的日期選擇器(Date Picker),未使用第三方插件 https://blog.csdn.net/qq_33650655/article/details/145673279
-
DeepSeek 助力 Vue 開發:打造絲滑的顏色選擇器(Color Picker)https://blog.csdn.net/qq_33650655/article/details/145689522
-
DeepSeek 助力 Vue 開發:打造絲滑的右鍵菜單(RightClickMenu)https://blog.csdn.net/qq_33650655/article/details/145706658
-
DeepSeek 助力 Vue 開發:打造絲滑的范圍選擇器(Range Picker)https://blog.csdn.net/qq_33650655/article/details/145713572
-
DeepSeek 助力 Vue 開發:打造絲滑的導航欄(Navbar)https://blog.csdn.net/qq_33650655/article/details/145732421
-
DeepSeek 助力 Vue 開發:打造絲滑的表單驗證(Form Validation)https://blog.csdn.net/qq_33650655/article/details/145735582
-
DeepSeek 助力 Vue 開發:打造絲滑的復制到剪貼板(Copy to Clipboard)https://blog.csdn.net/qq_33650655/article/details/145739569
-
DeepSeek 助力 Vue 開發:打造絲滑的點擊動畫(Click Animations)https://blog.csdn.net/qq_33650655/article/details/145766184
-
DeepSeek 助力 Vue 開發:打造絲滑的縮略圖列表(Thumbnail List)https://blog.csdn.net/qq_33650655/article/details/145776679
-
DeepSeek 助力 Vue 開發:打造絲滑的 鍵盤快捷鍵(Keyboard Shortcuts) https://blog.csdn.net/qq_33650655/article/details/145780227
-
DeepSeek 助力 Vue 開發:打造絲滑的評論系統(Comment System)https://blog.csdn.net/qq_33650655/article/details/145781104
-
DeepSeek 助力 Vue 開發:打造絲滑的二維碼生成(QR Code)https://blog.csdn.net/qq_33650655/article/details/145797928
到此這篇文章就介紹到這了,更多精彩內容請關注本人以前的文章或繼續瀏覽下面的文章,創作不易,如果能幫助到大家,希望大家多多支持寶碼香車~💕,若轉載本文,一定注明本文鏈接。
更多專欄訂閱推薦:
👍 html+css+js 絢麗效果
💕 vue
?? Electron
?? js
📝 字符串
?? 時間對象(Date())操作