vue移動端項目vant組件庫之tag詳解
vant組件庫之tag
直接上代碼
<template> ? <div class="pd50"> ? ? <!-- Tag標簽的屬性與Button按鈕的大體相同 --> ? ? <!-- 基礎用法? ? ? ? ? 其他第三方ui庫的顏色可能不一致 ? ? --> ? ? <h2>基礎用法</h2> ? ? <van-tag type="primary">標簽</van-tag> ? ? <van-tag type="success">標簽</van-tag> ? ? <van-tag type="danger">標簽</van-tag> ? ? <van-tag type="warning">標簽</van-tag> ? ? <!-- 空心樣式? ? ? ? ? 多數(shù)第三方都是采用 plain 作為空心樣式 ? ? --> ? ? <h2>空心樣式</h2> ? ? <van-tag plain type="primary">標簽</van-tag> ? ? <h2>圓角</h2> ? ? <van-tag round type="primary">標簽</van-tag> ? ? <h2>標記樣式 半圓角</h2> ? ? <van-tag mark type="primary">標簽</van-tag> ? ? <h2>可關閉標簽</h2> ? ? <!-- 需要自己寫邏輯控制關閉 --> ? ? <van-tag v-if="show" closeable type="primary" @close="close"> ? ? ? 標簽 ? ? </van-tag> ? ? <h2>大小</h2> ? ? <van-tag type="primary">標簽</van-tag> ? ? <van-tag type="primary" size="medium">標簽</van-tag> ? ? <van-tag type="primary" size="large">標簽</van-tag> ? ? <h2>自定義顏色</h2> ? ? <!--? ? ? ? ? color 背景顏色 ? ? ? ? text-color 文本顏色 ? ? ?--> ? ? <van-tag color="#7232dd">標簽</van-tag> ? ? <van-tag color="#ffe1e1" text-color="#e44e44">標簽</van-tag> ? ? <van-tag color="#7232dd" plain>標簽</van-tag> ? ? <h2>漸變色沒有起作用,后續(xù)博文處理該問題</h2> ? ? <van-tag color="linear-gradient(to right, #ff6034, #ee0a24)">我是漸變tag</van-tag> ? ? <!-- ?--> ? ? <h2>其他</h2> ? ? <div>內(nèi)容是個默認插槽, 也就是說可以進行一些額外的布局</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標簽選中(類型選擇,分類選擇)
使用三元表達式為類選擇器給值。當變量active被點擊賦值時則,引用active樣式。無點擊使用Classification樣式。
往往就是簡單的操作,就把自己玩懵逼了!寫半天報找不到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;
}以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue2.0 computed 計算list循環(huán)后累加值的實例
下面小編就為大家分享一篇vue2.0 computed 計算list循環(huán)后累加值的實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-03-03
Vue?2源碼閱讀?Provide?Inject?依賴注入詳解
這篇文章主要為大家介紹了Vue?2源碼閱讀?Provide?Inject?依賴注入詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-08-08
在使用uni-data-select插件時通過接口獲取值賦給localdata失敗的問題解決方案
在加載渲染時,調(diào)取接口請求的是一個異步的操作,在子組件拿到數(shù)據(jù)前就渲染了,才導致子組件watch沒有監(jiān)聽到值的變化,下面給大家介紹在使用uni-data-select插件時通過接口獲取值賦給localdata失敗的問題,感興趣的朋友一起看看吧2024-12-12
vue將data恢復到初始狀態(tài) && 重新渲染組件實例
這篇文章主要介紹了vue將data恢復到初始狀態(tài) && 重新渲染組件實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09

