在使用Elemet编辑前端页面中,也许会需要使用多选框。在Element中有官方设定好的标签el-checkbox的标签可以生成多选框。它2分为两种,一种是基础的多选框,还有一种是多选框组el-checkbox-group。
<el-checkbox v-model="checked">备选项</el-checkbox>
和
<el-checkbox-group
v-model="checkedCities">
<el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox>
</el-checkbox-group>
在使用el-checked-group时,v-model属性绑定的是默认选中的集合,可以使用动态数据进行回显。在el-checkbox 中v-for绑定的是要遍历的数据集合。
我们可以在代码块中进行定义
export default {
data() {
return {
checkedCities:[],
cities:[]
}
}
然后通过axios技术去后台进行加载
this.axios.get('后台访问地址').then((response) => {
this.cities = response.data;
});