亚洲中字慕日产2020,大陆极品少妇内射AAAAAA,无码av大香线蕉伊人久久,久久精品国产亚洲av麻豆网站

資訊專(zhuān)欄INFORMATION COLUMN

表單選項(xiàng)互斥問(wèn)題(vue)

shiyang6017 / 2742人閱讀

摘要:最近有一個(gè)需求表單中有個(gè)多選框,而他們的選項(xiàng)是一樣的,但是如果其中一個(gè)選項(xiàng)被選擇之后,在另外個(gè)多選框里面就不能再選了。上代碼乒乓球放入不同的盒子選項(xiàng)互斥每個(gè)對(duì)象都有一個(gè)屬性,用來(lái)表示它屬于哪個(gè)盒子。

最近有一個(gè)需求:
表單中有3個(gè)多選框,而他們的選項(xiàng)是一樣的,但是如果其中一個(gè)選項(xiàng)被選擇之后,在另外2個(gè)多選框里面就不能再選了。
這樣的問(wèn)題,讓我想到了“將乒乓球放入不同盒子”的例子。

上代碼

// index.html



    
        
        
        
        Document

        
        
    
    
        

乒乓球放入不同的盒子(選項(xiàng)互斥)

// main.js

const balls = Array(12)
    .fill(undefined)
    .map((v, i) => ({ id: i < 9 ? `0${i + 1}` : i + 1, category: null }))

const vm = new window.Vue({
    el: "#app",

    data: () => ({
        msg: "hahahhaha",
        balls,
        categories: ["red", "green", "blue"],
        currCategory: "red"
    }),

    computed: {
        ballList() {
            return this.balls.map(v => {
                let className = ["ping-pong-ball"]
                if (v.category) {
                    className.push(v.category)
                    if (v.category !== this.currCategory) {
                        className.push("disable")
                    }
                }
                return { ...v, className }
            })
        }
    },

    methods: {
        onBoxClick(category) {
            if (category !== this.currCategory) {
                this.currCategory = category
            }
        },

        onBallClick(id) {
            const ball = this.balls.find(v => v.id === id)
            if (ball) {
                ball.category = ball.category ? null : this.currCategory
            }
        }
    }
})
// styles.css

#app {
    user-select: none;
}

.ping-pong-list {
    display: flex;
    margin: 20px;
    justify-content: center;
    flex-wrap: wrap;
}

.ping-pong-ball {
    width: 50px;
    height: 50px;
    margin: 5px;
    border-radius: 50%;
    box-shadow: 0 0 10px 0 #aaa;
    text-align: center;
    line-height: 50px;
}

.ping-pong-list .ping-pong-ball {
    cursor: pointer;
}

.box-wrapper {
    display: flex;
    justify-content: space-around;
    margin-top: 30px;
}

.box {
    display: flex;
    align-content: flex-start;
    flex-wrap: wrap-reverse;
    width: 300px;
    height: 200px;
    border: 10px solid;
    border-top-width: 0;
    cursor: pointer;
    transition: all 0.25s;
}

.box.red {
    border-color: rgb(238, 97, 97);
}

.box.green {
    border-color: rgb(97, 238, 156);
}

.box.blue {
    border-color: rgb(97, 146, 238);
}

.box.active {
    box-shadow: 0 10px 20px 0 #aaa;
}

.ping-pong-ball.red,
.box.red .ping-pong-ball {
    background-color: rgb(238, 97, 97);
}

.ping-pong-ball.green,
.box.green .ping-pong-ball {
    background-color: rgb(97, 238, 156);
}

.ping-pong-ball.blue,
.box.blue .ping-pong-ball {
    background-color: rgb(97, 146, 238);
}

.ping-pong-ball.disable {
    opacity: 0.25;
    pointer-events: none;
}

每個(gè)ball對(duì)象都有一個(gè)category屬性,用來(lái)表示它屬于哪個(gè)盒子。然后在渲染的時(shí)候,根據(jù)category來(lái)計(jì)算使用的類(lèi)名。

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/101994.html

相關(guān)文章

  • Vue.js-表單與v-model

    摘要:學(xué)習(xí)筆記表單與表單與提供了指令,用于在表單類(lèi)元素上雙向綁定數(shù)據(jù)。事實(shí)上,也是一個(gè)特殊的語(yǔ)法糖,只不過(guò)它會(huì)在不同的表單上智能處理。選擇的項(xiàng)復(fù)選框復(fù)選框單獨(dú)使用時(shí),也是用綁定一個(gè)布爾值。復(fù)選框選擇列表當(dāng)選中時(shí),是一個(gè),所以。 學(xué)習(xí)筆記:表單與v-model 表單與v-model Vue.js提供了v-model指令,用于在表單類(lèi)元素上雙向綁定數(shù)據(jù)。 使用v-model后,表單控件顯示的值...

    jollywing 評(píng)論0 收藏0
  • Vue2.0 實(shí)現(xiàn)互斥

    摘要:需要實(shí)現(xiàn)如上圖的功能首次加載頁(yè)面,根據(jù)里的高亮對(duì)應(yīng)的選項(xiàng)點(diǎn)擊某個(gè)選項(xiàng),該選項(xiàng)高亮,其他去掉高亮代碼結(jié)構(gòu)自我理解參考鏈接 showImg(https://segmentfault.com/img/bV8k6F?w=929&h=182); 需要實(shí)現(xiàn)如上圖的功能 1. 首次加載頁(yè)面,根據(jù)data里的catgoryId高亮對(duì)應(yīng)的選項(xiàng) 2. 點(diǎn)擊某個(gè)選項(xiàng),該選項(xiàng)高亮,其他去掉高亮 代碼結(jié)構(gòu): ...

    endiat 評(píng)論0 收藏0
  • 使用Vue渲染可配置表單--記一次問(wèn)卷平臺(tái)項(xiàng)目

    摘要:相當(dāng)于可以編輯問(wèn)卷并提供問(wèn)卷展示,數(shù)據(jù)統(tǒng)計(jì)的這么一個(gè)平臺(tái)。極大的節(jié)省了需要進(jìn)行表單樣式修改的時(shí)間,同時(shí),讓動(dòng)態(tài)渲染表單成為一件可能且容易的事情。表單動(dòng)態(tài)渲染剛好在項(xiàng)目之前,有過(guò)一次動(dòng)態(tài)配置表單的嘗試通過(guò)字段自動(dòng)生成表單及驗(yàn)證。 近幾天來(lái)了個(gè)緊急項(xiàng)目,想要做一個(gè)內(nèi)部版本的問(wèn)卷星。相當(dāng)于可以編輯問(wèn)卷并提供問(wèn)卷展示,數(shù)據(jù)統(tǒng)計(jì)的這么一個(gè)平臺(tái)。整個(gè)項(xiàng)目耗時(shí)不長(zhǎng),本著積淀和積累的原則,將過(guò)程中的...

    mcterry 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<