欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue實(shí)現(xiàn)文章點(diǎn)贊和差評功能

 更新時(shí)間:2022年04月14日 14:30:30   作者:每一份筆記都是美好回憶  
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)文章點(diǎn)贊和差評功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了vue實(shí)現(xiàn)文章點(diǎn)贊和差評功能的具體代碼,供大家參考,具體內(nèi)容如下

純前端實(shí)現(xiàn)文章點(diǎn)贊與差評(支持與不支持)。

需求:狀態(tài)1:用戶沒有操作過,即既沒點(diǎn)贊和差評;狀態(tài)二:用戶點(diǎn)贊過;狀態(tài)三:用戶差評過。點(diǎn)贊或差評過后無法取消,可切換。如下圖:

dom結(jié)構(gòu):

<!-- 頂 -->
? ? ? <view class="flex-1 flex ai-center jc-center animate__animated animate__fast" hover-class="animate__jello text-main"
? ? ? ? @click="DoSupport('support')" :class="item.support.type === 'support'? 'support-active':''">
? ? ? ? <text class="iconfont icon-dianzan2 mr-2"></text>
? ? ? ? <text>{{item.support.support_count}}</text>
? ? ? </view>
? ? ? <!-- 踩 -->
? ? ? <view class="flex-1 flex ai-center jc-center animate__animated animate__fast" hover-class="animate__jello text-main"
? ? ? ? @click="DoSupport('unsupport')" :class="item.support.type === 'unsupport'? 'support-active':''">
? ? ? ? <text class="iconfont icon-cai mr-2"></text>
? ? ? ? <text>{{item.support.unsupport_count}}</text>
</view>

list數(shù)據(jù):

const demo = [{
? ? username: "昵稱",
? ? userpic: "/static/tabber/indexSelected.png",
? ? newstime: "2021-1-1 下午1:00",
? ? isFollow: false,
? ? title: "我是標(biāo)題",
? ? titlepic: "/static/2956568.jpg",
? ? support: {
? ? ? type: "support", //支持
? ? ? support_count: 1,
? ? ? unsupport_count: 2
? ? },
? ? comment_count: 2,
? ? share_num: 2
? }, {
? ? username: "昵稱",
? ? userpic: "/static/tabber/indexSelected.png",
? ? newstime: "2021-1-1 下午1:00",
? ? isFollow: false,
? ? title: "我是標(biāo)題",
? ? titlepic: "/static/2956568.jpg",
? ? support: {
? ? ? type: "unsupport", //不支持
? ? ? support_count: 1,
? ? ? unsupport_count: 2
? ? },
? ? comment_count: 2,
? ? share_num: 2
? }, {
? ? username: "昵稱",
? ? userpic: "/static/tabber/indexSelected.png",
? ? newstime: "2021-1-1 下午1:00",
? ? isFollow: false,
? ? title: "我是標(biāo)題",
? ? titlepic: "/static/2956568.jpg",
? ? support: {
? ? ? type: "", //無操作
? ? ? support_count: 1,
? ? ? unsupport_count: 2
? ? },
? ? comment_count: 2,
? ? share_num: 2
? }]

list數(shù)組每個(gè)item定義了一個(gè)type,當(dāng)type為support則為 支持;當(dāng)type為unsupport則為不支持;當(dāng)type為空時(shí)則為無操作。

點(diǎn)擊方法:點(diǎn)擊之后子組件通知父組件并傳遞點(diǎn)擊的是哪篇文章(index),點(diǎn)擊的是贊還是踩(支持還是不支持)

// 頂踩操作
DoSupport(type) {
? ? ? ? // 通知父組件
? ? ? ? this.$emit('doSupport', {
? ? ? ? ? type: type,
? ? ? ? ? index: this.index
? ? ? ? })
}

父組件中接收:

邏輯是:

拿到當(dāng)前對象:let item = this.list[e.index]

1.如果是之前沒有操作過,則改變它的type,并讓它的相對應(yīng)的count加1;

2.如果是之前頂過,現(xiàn)在點(diǎn)踩,那么則改變它的type為unsupport,并讓頂?shù)腸ount數(shù)減一同時(shí)踩的count數(shù)加一;

3.如果是之前踩過,現(xiàn)在點(diǎn)贊,那么則改變它的type為support,并讓頂?shù)腸ount數(shù)加一同時(shí)踩的count數(shù)減一;

// 頂踩操作
doSupport(e) {
? ? ? ? // 拿到當(dāng)前對象
? ? ? ? let item = this.list[e.index]
? ? ? ? // 之前沒有操作過
? ? ? ? if (item.support.type === '') {
? ? ? ? ? item.support.type = e.type
? ? ? ? ? item.support[e.type + '_count']++
? ? ? ? ? return
? ? ? ? }
? ? ? ? // 之前頂過
? ? ? ? if (item.support.type === 'support' && e.type === 'unsupport') {
? ? ? ? ? item.support.type = e.type
? ? ? ? ? // 踩+1
? ? ? ? ? item.support.unsupport_count++
? ? ? ? ? // 頂-1
? ? ? ? ? item.support.support_count--
? ? ? ? ? return
? ? ? ? }
? ? ? ? // 之前踩過
? ? ? ? if (item.support.type === 'unsupport' && e.type === 'support') {
? ? ? ? ? item.support.type = e.type
? ? ? ? ? // 頂+1
? ? ? ? ? item.support.support_count++
? ? ? ? ? // 踩-1
? ? ? ? ? item.support.unsupport_count--
? ? ? ? ? return
? ? ? ? }
? ? ? },

如此,文章的點(diǎn)贊與差評的代碼已完成。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue+iview 實(shí)現(xiàn)可編輯表格的示例代碼

    vue+iview 實(shí)現(xiàn)可編輯表格的示例代碼

    這篇文章主要介紹了vue+iview 實(shí)現(xiàn)可編輯表格的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-10-10
  • vue-resource調(diào)用promise取數(shù)據(jù)方式詳解

    vue-resource調(diào)用promise取數(shù)據(jù)方式詳解

    這篇文章主要介紹了vue-resource調(diào)用promise取數(shù)據(jù)方式詳解,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-07-07
  • vue中實(shí)現(xiàn)支持txt,docx,xlsx,mp4格式文件預(yù)覽功能(純前端)

    vue中實(shí)現(xiàn)支持txt,docx,xlsx,mp4格式文件預(yù)覽功能(純前端)

    對于Vue你可以實(shí)現(xiàn)文件的預(yù)覽功能,這篇文章主要給大家介紹了關(guān)于vue中實(shí)現(xiàn)支持txt,docx,xlsx,mp4格式文件預(yù)覽功能的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-11-11
  • vue解決this.$refs.xx在mounted中獲取DOM元素為undefined問題

    vue解決this.$refs.xx在mounted中獲取DOM元素為undefined問題

    這篇文章主要介紹了vue解決this.$refs.xx在mounted中獲取DOM元素為undefined問題,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • vue中的slot封裝組件彈窗

    vue中的slot封裝組件彈窗

    這篇文章主要介紹了vue中的slot封裝組件彈窗,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Vue利用draggable實(shí)現(xiàn)多選拖拽效果

    Vue利用draggable實(shí)現(xiàn)多選拖拽效果

    這篇文章主要為大家詳細(xì)介紹了如何利用vue中的draggable插件實(shí)現(xiàn)多選拖拽效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-05-05
  • :visible.sync 的作用詳解

    :visible.sync 的作用詳解

    我們在前端開發(fā)中經(jīng)常看到:visible.sync這種修飾符,很多人不知道這是干什么的,在使用ElementUI的時(shí)候,里面有個(gè)彈窗el-dialog組件的時(shí)候會有用到:visible.sync,今天小編帶領(lǐng)大家學(xué)習(xí)下:visible.sync 的作用,感興趣的朋友一起看看吧
    2022-11-11
  • vue項(xiàng)目打包部署后默認(rèn)路由不正確的解決方案

    vue項(xiàng)目打包部署后默認(rèn)路由不正確的解決方案

    這篇文章主要介紹了vue項(xiàng)目打包部署后默認(rèn)路由不正確的解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • Vue中如何實(shí)現(xiàn)字符串換行

    Vue中如何實(shí)現(xiàn)字符串換行

    這篇文章主要介紹了Vue中如何實(shí)現(xiàn)字符串換行問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • Vue導(dǎo)出Excel功能的全過程記錄

    Vue導(dǎo)出Excel功能的全過程記錄

    在開發(fā)后臺管理系統(tǒng)的時(shí)候,很多地方都要用到導(dǎo)出excel 表格,比如將table中的數(shù)據(jù)導(dǎo)出到本地,這篇文章主要給大家介紹了關(guān)于Vue導(dǎo)出Excel功能的相關(guān)資料,需要的朋友可以參考下
    2021-07-07

最新評論