Element-ui框架checkbox復選框回顯


          

    

先看下效果是不是你需要的。。。。。

 

 然后廢話不多說,上代碼,希望能夠幫助到你。。。

 

 1 <template>
 2     <div class=''>
 3          <el-form label-width="100px" class="demo-ruleForm">
 4             <el-form-item>
 5               <el-checkbox-group v-model="favourableForm">
 6                 <el-checkbox v-for="(item,index) in favourables" @change="change(index,item)" :label="item.id" :value="item.id" :key="item.id" name="type" class="favour_checkbox">{{item.preferentialName}}</el-checkbox>
 7               </el-checkbox-group>
 8             </el-form-item>
 9         </el-form>    
10     </div>
11 </template>
12     
13 <script>
14 export default {
15     props: {
16         message: Object
17     },
18     data() {
19         return {
20           favourableForm:[],  //選中的數據
21           favourables:[]  //初始化賦值
22         }
23     },
24     methods: {
25        change(index,item){
26             item.containPreferential==0?this.favourables[index].containPreferential=1:this.favourables[index].containPreferential=0;
27             this.$axios.post('/clapi/materiel/mealPreferentialRela/editPreferentialManage',this.favourables)
28             .then((response) => {
29             })
30             .catch((error) => {
31               this.$message({
32                 type: "warning",
33                 message: error.response.data.result
34               });
35             });
36           },
37         preferentialManage(){
38           this.$axios.get('/clapi/materiel/mealPreferentialRela/queryPreferentialManage?mealId='+this.message.id)
39           .then((response) => {
40             if(response.data.status.code == 200){
41               this.favourables = response.data.result;
42               for(let i=0;i<this.favourables.length;i++){
43                 if(this.favourables[i].containPreferential==1){
44                   this.favourableForm.push(this.favourables[i].id);
45                 }
46               }
47             }
48           })
49           .catch((error) => {
50             this.$message({
51               type: "warning",
52               message: error.response.data.result
53             });
54           });
55         }
56       },
57       created(){
58         this.mealId = this.message.id;
59         this.preferentialManage();
60       }
61  }
62 </script>
63 <style scoped>
64 .favour_checkbox{
65   display:block;
66   height:60px;
67   margin-left:0px;
68 }
69 </style>

 

 

 

若有不明白請加群號:復制 695182980 ,也可掃碼,希望能幫助到大家。

               


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM