讓這兩個select相互系結,讓roleOptions選取值后,worklist彈出得是roleOptions值
<el-select v-model="postForm.projectName" placeholder="請選擇" @change="getList(postForm)"> <el-option v-for="item in roleOptions" :key="item.key" :label="item.label" :value="https://www.cnblogs.com/jiyingaoshou/p/item.key"> </el-option> <el-select v-model="postForm" placeholder="請選擇" value-key="id" @change="getList2(postForm)"> <el-option v-for="item in worklist" :label="item.productName" :value="https://www.cnblogs.com/jiyingaoshou/p/item"> </el-option> 首先在created里面獲取值,設res為null,傳入getlist中; async created() { this.lastWorklist = await api_price_list({},this.queryParam); let res = null; this.getList(res) }, 然后在methods中進行判斷 methods: { async getList(res) { this.listLoading = true 如果res為null獲取worklist if(res != null){ this.worklist = []; 如果res里面的獲取資料為s或y則系結不同的值 if(res.projectName == "s"){ this.lastWorklist.data.list.forEach(item => { if(item.app == res.projectName){ this.worklist.push(item); } }); } else if(res.projectName == "y"){ this.lastWorklist.data.list.forEach(item => { if(item.app == res.projectName){ this.worklist.push(item); } }); } } this.listLoading = false }, 然后在getlist2里面在第二個select組件進行傳值系結 getList2(res){ if(res.app=="s"){ this.postForm.projectName = "抖音"; } else if(res.app == "y"){ this.postForm.projectName = "快手"; } },轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/34192.html
標籤:JavaScript
