vue手动实现多选框
Posted 嘴巴嘟嘟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vue手动实现多选框相关的知识,希望对你有一定的参考价值。
点击按钮选中,再点击其他按钮也都选中的业务需求
<p class="one-button" @click="commentFetch2(2,'pr2','productStatus','pr1','pr2','pr3','pr4','ProductStatus2')"></p>
首先注意的是这个数组只能接受四个数字,1,2,3,4. 所以我们首先对数据去重,然后取消点击的时候删除此时的数据,
let commentFetch2 = (key, value, type, val1, val2, val3, val4, istype) => {
state.params[type].push(key);
state.params[type] = [...new Set(state.params[type])];
if (value == val1) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
if (value == val2) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
if (value == val3) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
if (value == val4) {
state[istype] = !state[istype];
if (state[istype] === true) {
state.assetLists = [];
fetchData();
} else {
state.params[type].splice(state.params[type].findIndex(item => item === key), 1);
fetchData();
}
}
};
以上是关于vue手动实现多选框的主要内容,如果未能解决你的问题,请参考以下文章