vue如何實現(xiàn)動態(tài)的選中狀態(tài)切換效果
更新時間:2022年04月30日 11:11:59 作者:黑暗中跳舞的月亮
這篇文章主要介紹了vue如何實現(xiàn)動態(tài)的選中狀態(tài)切換效果,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
動態(tài)選中狀態(tài)切換效果
HTML中的內(nèi)容為以下。
<ul class="list">
? ? ?<li v-for="(item,index) in liList" v-on:click="addClass(index)" v-bind:class="{?
? ? ? ? ?ischeck:index==current}">{{item.title}}</li>
</ul>JS中的內(nèi)容為以下。
data () {
? ? return {
? ? ? ? ? ? current:0,
? ? ? ? ? ? liList:[
? ? ? ? ? ? ? ? {title:'中國'},
? ? ? ? ? ? ? ? {title:'美國'},
? ? ? ? ? ? ? ? {title:'英國'},
? ? ? ? ? ? ? ? {title:'法國'}
? ? ? ? ? ? ]
? ? }
},
methods:{?? ?
? ? addClass:function(index){
? ? ? ? ? this.current=index
? ? }
} ?CSS中的內(nèi)容如下。
.ischeck ?{
? ? background: #e6e6e6;
? ? height: 30px;
? ? width: 50px;
? ? line-height: 0px;
? ? padding: 15px 10px;
}vue狀態(tài)轉(zhuǎn)換
狀態(tài)展示
第一種方法
<el-table-column prop="sfgh" label="是否歸還" align="center"> ? ? ? ? ? ? ? ? <template scope="scope"> ? ? ? ? ? ? ? ? ? ? <p v-if="scope.row.sfgh=='0'"> ? ? ? ? ? ? ? ? ? ? ? ? <el-button ?href="javascript:void(0)" @click="getWzghInfo(scope.$index, scope.row)">已歸還</el-button> ? ? ? ? ? ? ? ? ? ? </p> ? ? ? ? ? ? ? ? ? ? <p v-if="scope.row.sfgh=='1'">未歸還</p> ? ? ? ? ? ? ? ? ? ? <p v-if="scope.row.sfgh=='2'">未還清</p> ? ? ? ? ? ? ? ? </template> ? ? ? ? ? ? </el-table-column>
第二種方法
使用formatter來實現(xiàn)
代碼如下:
<el-table-column label="狀態(tài)" :formatter="statusFormat">
</el-table-column>
methods: {
statusFormat: function(row, column) {
let status = row.status;
let statusW = "未繳費";
if(status == undefined) {
statusW = "未繳費";
}
switch(status) {
case 1:
statusW = "已繳費";
break;
case 2:
statusW = "退款申請中";
break;
}
return statusW;
}
}
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
vue如何修改data中的obj數(shù)據(jù)的屬性
這篇文章主要介紹了vue如何修改data中的obj數(shù)據(jù)的屬性,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
vuex中store存儲store.commit和store.dispatch的區(qū)別及說明
這篇文章主要介紹了vuex中store存儲store.commit和store.dispatch的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-09-09
vue iview實現(xiàn)動態(tài)路由和權限驗證功能
這篇文章主要介紹了vue iview實現(xiàn)動態(tài)路由和權限驗證功能,動態(tài)路由控制分為兩種:一種是將所有路由數(shù)據(jù)存儲在本地文件中,另一種則是本地只存儲基本路由,具體內(nèi)容詳情大家參考下此文2018-04-04

