Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.8k views
in Technique[技术] by (71.8m points)

这里的disabled为什么只生效一次,

想没勾选就disabled = false,勾选就true,我这个只生效一遍,第二次进来怎么点都是false...

<tr v-for="(item,index) in list" :key="item.id">
    <td class="checkbox">
        <el-checkbox v-model="item.sel"></el-checkbox>
    </td>
</tr>

<div :disabled= "disabled">提交订单</div>


this.list = [
    {
        sel:false
    },
    {
        sel:false
    }
]

//勾选触发监听
this.list.forEach(i => {
    if (i.sel) {
        this.disabled = false
    }
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

从楼主提供的代码中只看到disabled变量的赋值,没看到在html中使用。
checkbox中disable是禁用状态,选中状态是checked。
如果按照楼主的意思,没勾选disable=false,这时候checkbox是不能点击的禁用状态,没办法选中。
楼主是不是把:checked属性赋值给disable了?

<el-checkbox v-model="item.sel" :checked="disable"></el-checkbox>

那么监听勾选动作时就应该

//勾选触发监听
this.list.forEach(i => {
    if (i.sel) {
        this.disabled = true
    }
})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...