vue使用select間相互綁定


    

讓這兩個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="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="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 = "快手";
  }
},


免責聲明!

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