關(guān)于vue的列表圖片選中打鉤操作
首先 css,美化checkbox樣式,這一段代碼拿過去可以直接用
label { font-size: 25px; cursor: pointer; position: absolute; top: -10px; right: 0px; z-index: 150; } label i { font-size: 15px; font-style: normal; display: inline-block; width: 18px; border-radius: 15px; height: 18px; text-align: center; line-height: 18px; color: #fff; vertical-align: middle; margin: -2px 2px 1px 0px; border: #53c7f0 1px solid; } input[type="checkbox"], input[type="radio"] { display: none; outline: none; } input[type="radio"]+i { border-radius: 7px; } input[type="checkbox"]:checked+i, input[type="radio"]:checked+i { background: #fff; color: #53c7f0; }
接著是內(nèi)容部分,這里變量命名比較亂,但是效果都是通過變量控制的,主要思路是點(diǎn)擊后,將一個(gè)id傳入一個(gè)臨時(shí)數(shù)組,再遍歷這個(gè)臨時(shí)數(shù)組,拿數(shù)組中的值與當(dāng)前值對(duì)比,如果對(duì)比成功,那么就讓選中的checkbox顯示出來
相對(duì)的,如果想要提交,那么只需要將臨時(shí)數(shù)組傳進(jìn)去就好了
<div class="t-recommed-r" v-for="(item,index) in list" :key="index"> <p><span></span> {{ item.name }} <span></span></p> <ul> <li v-for="(val,key) in item.data" :key="key" @click="checkTab(val.id)"> <label v-for="(v, k) in checkedList" :key="k" v-show="val.id === v"> <input type="checkbox" :checked="val.id === v"> <i>✓</i> </label> <a><img src="@/assets/images/null.png"><em>{{ val.name }}</em></a> </li> </ul> </div>
最后一步,js部分
data () { return { checkedList: [], list: [] } }, methods: { checkTab (id) { let index = this.checkedList.indexOf(id) if (index === -1) { this.checkedList.push(id) } else { this.checkedList.splice(index, 1) } }, } // 如果存在數(shù)組中,那么進(jìn)行刪除操作, 如果不存在,則放入數(shù)組中
補(bǔ)充知識(shí):vue列表獲取勾選的內(nèi)容并打印
先將勾選的內(nèi)容通過彈出層顯示出來
showPrintData: function() { var id = this.checkedList[0].id; axios.post(this.$api.contentGet, { id: id }).then(res => { this.contentTxt = res.body.txt; this.dialogFormVisible=true; }); },
contentTxt: "",
dialogFormVisible: false,
<el-dialog :visible.sync="dialogFormVisible"> <div ref="print" v-html="contentTxt"> {{contentTxt}} </div> <div slot="footer" class="dialog-footer"> <el-button type="primary" @click="printData()">打印</el-button> </div> </el-dialog>
然后進(jìn)行打印
printData: function() { this.$print(this.$refs.print); },
說明:
vue框架使用是element
打印使用的插件地址:https://github.com/xyl66/vuePlugs_printjs
在main.js中進(jìn)行注冊(cè)
import Print from '@/plugs/print'
Vue.use(Print);
以上這篇關(guān)于vue的列表圖片選中打鉤操作就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- Vue實(shí)現(xiàn)一個(gè)無限加載列表功能
- Vue 列表頁帶參數(shù)進(jìn)詳情頁的操作(router-link)
- vue 公共列表選擇組件,引用Vant-UI的樣式方式
- vue實(shí)現(xiàn)前端列表多條件篩選
- vue實(shí)現(xiàn)點(diǎn)擊按鈕“查看詳情”彈窗展示詳情列表操作
- vue-列表下詳情的展開與折疊案例
- vue v-for出來的列表,點(diǎn)擊某個(gè)li使得當(dāng)前被點(diǎn)擊的li字體變紅操作
- vue實(shí)現(xiàn)循環(huán)滾動(dòng)列表
- vue實(shí)現(xiàn)列表滾動(dòng)的過渡動(dòng)畫
- 如何讓vue長(zhǎng)列表快速加載
相關(guān)文章
vue3 reactive定義的引用類型直接賦值導(dǎo)致數(shù)據(jù)失去響應(yīng)式問題
這篇文章主要介紹了vue3 reactive定義的引用類型直接賦值導(dǎo)致數(shù)據(jù)失去響應(yīng)式問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-06-06Vue3中如何修改父組件傳遞到子組件中的值(全網(wǎng)少有!)
大家都知道,vue是具有單向數(shù)據(jù)流的傳遞特性,下面這篇文章主要給大家介紹了關(guān)于Vue3中如何修改父組件傳遞到子組件中值的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04使用Element+vue實(shí)現(xiàn)開始與結(jié)束時(shí)間限制
這篇文章主要為大家詳細(xì)介紹了使用Element+vue實(shí)現(xiàn)開始與結(jié)束時(shí)間限制,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08elementUI同一頁面展示多個(gè)Dialog的實(shí)現(xiàn)
這篇文章主要介紹了elementUI同一頁面展示多個(gè)Dialog的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11Vue + Element-ui的下拉框el-select獲取額外參數(shù)詳解
這篇文章主要介紹了Vue + Element-ui的下拉框el-select獲取額外參數(shù)詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-08-08