vue移動(dòng)端項(xiàng)目vant組件庫(kù)之tag詳解
vant組件庫(kù)之tag
直接上代碼
<template> ? <div class="pd50"> ? ? <!-- Tag標(biāo)簽的屬性與Button按鈕的大體相同 --> ? ? <!-- 基礎(chǔ)用法? ? ? ? ? 其他第三方ui庫(kù)的顏色可能不一致 ? ? --> ? ? <h2>基礎(chǔ)用法</h2> ? ? <van-tag type="primary">標(biāo)簽</van-tag> ? ? <van-tag type="success">標(biāo)簽</van-tag> ? ? <van-tag type="danger">標(biāo)簽</van-tag> ? ? <van-tag type="warning">標(biāo)簽</van-tag> ? ? <!-- 空心樣式? ? ? ? ? 多數(shù)第三方都是采用 plain 作為空心樣式 ? ? --> ? ? <h2>空心樣式</h2> ? ? <van-tag plain type="primary">標(biāo)簽</van-tag> ? ? <h2>圓角</h2> ? ? <van-tag round type="primary">標(biāo)簽</van-tag> ? ? <h2>標(biāo)記樣式 半圓角</h2> ? ? <van-tag mark type="primary">標(biāo)簽</van-tag> ? ? <h2>可關(guān)閉標(biāo)簽</h2> ? ? <!-- 需要自己寫邏輯控制關(guān)閉 --> ? ? <van-tag v-if="show" closeable type="primary" @close="close"> ? ? ? 標(biāo)簽 ? ? </van-tag> ? ? <h2>大小</h2> ? ? <van-tag type="primary">標(biāo)簽</van-tag> ? ? <van-tag type="primary" size="medium">標(biāo)簽</van-tag> ? ? <van-tag type="primary" size="large">標(biāo)簽</van-tag> ? ? <h2>自定義顏色</h2> ? ? <!--? ? ? ? ? color 背景顏色 ? ? ? ? text-color 文本顏色 ? ? ?--> ? ? <van-tag color="#7232dd">標(biāo)簽</van-tag> ? ? <van-tag color="#ffe1e1" text-color="#e44e44">標(biāo)簽</van-tag> ? ? <van-tag color="#7232dd" plain>標(biāo)簽</van-tag> ? ? <h2>漸變色沒有起作用,后續(xù)博文處理該問題</h2> ? ? <van-tag color="linear-gradient(to right, #ff6034, #ee0a24)">我是漸變tag</van-tag> ? ? <!-- ?--> ? ? <h2>其他</h2> ? ? <div>內(nèi)容是個(gè)默認(rèn)插槽, 也就是說(shuō)可以進(jìn)行一些額外的布局</div> ? ? <van-tag type="success" plain><span style="color:#347ad0">我可以</span></van-tag> ? ? <van-tag type="success" plain> ? ? ? ? <img src="@/assets/1.jpg" alt=""> ? ? </van-tag> ? </div> </template>
<script> import { Tag } from "vant"; export default { ? components: { ? ? vanTag: Tag, ? }, ? data() { ? ? return { ? ? ? show: true, ? ? }; ? }, ? methods: { ? ? close() { ? ? ? this.show = false; ? ? }, ? }, }; </script> <style lang="scss" scoped> </style>
效果
tag標(biāo)簽選中(類型選擇,分類選擇)
使用三元表達(dá)式為類選擇器給值。當(dāng)變量active被點(diǎn)擊賦值時(shí)則,引用active樣式。無(wú)點(diǎn)擊使用Classification樣式。
往往就是簡(jiǎn)單的操作,就把自己玩懵逼了!寫半天報(bào)找不到Classification,還在想誒?Classification不是變量啊。一臉懵逼。最后發(fā)現(xiàn)'active':'Classification'。沒加''。(日常自己坑自己)
效果圖:
<div v-for="(item,index) in data"> <span :class="active==item.type?'active':'Classification'" @click="oncheck(item.type)"> {{item.type}}</span> </div>
js:
data() { return { data: [{ type: '66P' }, { type: '760P' }, { type: '(含16G系統(tǒng)優(yōu)盤)660P' }, { type: '(含16G系統(tǒng)優(yōu)化盤)760P' }], active:'' } }, methods: { oncheck(name){ console.log(name) this.active=name } }
css:
.active{ float: left; margin-left: 10px; padding: 10px; background: #efc531; margin-bottom: 10px; border-radius: 4px; font-size: 14px; } .Classification { float: left; margin-left: 10px; padding: 10px; background: #f7f7f7; margin-bottom: 10px; border-radius: 4px; font-size: 14px; }
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue如何通過(guò)點(diǎn)擊事件彈出彈窗頁(yè)面詳解
彈窗是我們開發(fā)中經(jīng)常遇到的一個(gè)功能,下面這篇文章主要給大家介紹了關(guān)于vue如何通過(guò)點(diǎn)擊事件彈出彈窗頁(yè)面的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06vue2.0 computed 計(jì)算list循環(huán)后累加值的實(shí)例
下面小編就為大家分享一篇vue2.0 computed 計(jì)算list循環(huán)后累加值的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-03-03Vue?2源碼閱讀?Provide?Inject?依賴注入詳解
這篇文章主要為大家介紹了Vue?2源碼閱讀?Provide?Inject?依賴注入詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08Vue3環(huán)境安裝以及項(xiàng)目搭建全過(guò)程
Vue工程化項(xiàng)目環(huán)境配置還是比較麻煩的,下面這篇文章主要給大家介紹了關(guān)于Vue3環(huán)境安裝以及項(xiàng)目搭建的相關(guān)資料,文中通過(guò)圖文以及代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-12-12在使用uni-data-select插件時(shí)通過(guò)接口獲取值賦給localdata失敗的問題解決方案
在加載渲染時(shí),調(diào)取接口請(qǐng)求的是一個(gè)異步的操作,在子組件拿到數(shù)據(jù)前就渲染了,才導(dǎo)致子組件watch沒有監(jiān)聽到值的變化,下面給大家介紹在使用uni-data-select插件時(shí)通過(guò)接口獲取值賦給localdata失敗的問題,感興趣的朋友一起看看吧2024-12-12關(guān)于vue項(xiàng)目部署后刷新網(wǎng)頁(yè)報(bào)404錯(cuò)誤解決
這篇文章主要介紹了關(guān)于vue項(xiàng)目部署后刷新網(wǎng)頁(yè)報(bào)404錯(cuò)誤解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07vue利用axios來(lái)完成數(shù)據(jù)的交互
這篇文章主要介紹了vue利用axios來(lái)完成數(shù)據(jù)的交互,本文通過(guò)實(shí)例代碼給大家講解數(shù)據(jù)交互方法及安裝方法,需要的朋友可以參考下2018-03-03vue將data恢復(fù)到初始狀態(tài) && 重新渲染組件實(shí)例
這篇文章主要介紹了vue將data恢復(fù)到初始狀態(tài) && 重新渲染組件實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09