Vue2结合Element UI构建项目-select结合raido使用

想实现的效果是,有个radio组,给出一些列值,选择一个值的话,select组件带上相应值请求,请求结果供选择

组件模板中代码:

 <el-select v-model="request_id" placeholder="请选择requestId">
    <el-option
      v-for="(item,index) in request_ids"
      :key="index"
      :label="item"
      :value="item">
    </el-option>
</el-select>
<el-radio-group v-model="period" @change="chang_period">
    <el-radio :label="1">1分钟内</el-radio>
    <el-radio :label="5">5分钟内</el-radio>
    <el-radio :label="30">30分钟内</el-radio>
    <el-radio :label="60">1小时内</el-radio>
  </el-radio-group>

组件中:

 export default {
       name:"Catelog",
       data(){
           return{      
               period:60,
               request_ids:[],
               request_id:""
           }
       },
      
        mounted:function(){
          this.showid=this.$route.params.showid
       this.$get("/xxx/xxx/"+this.showid/this.period).then((response)=>{
            if (response.suc==1||response.suc=="1")
            {
            this.resp_data=response.data;
            this.request_ids=this.resp_data.request_ids
            }else{
              this.request_ids=[]
              this.request_id=""
            }
       })},
       methods:{
       
        chang_period:function(){
         let url="/XXX/xxx/"+this.showid+"/"+this.period
        this.$get(url).then((response)=>{
             if (response.suc==1||response.suc=="1")
             {
             this.resp_data=response.data;
             this.request_ids=this.resp_data.request_ids
             }else{
               this.request_ids=[]
               this.request_id=""
           }
          
           })
         }
       }
     
   }

data中定义初始值

period:60, //radio默认选中的值
request_ids:[],//select options选项
request_id:""//select选中的值 

mounted中定义页面加载时去请求period默认值的request_ids值。
methods中定义chang_period函数,这是radio值改变后的调用函数,带着新的radio值去请求request_ids值。
模板值的raido组件值绑定chang_period

 @change="chang_period"

注意,若是没有请求到值的话,需要将request_ids置空,防止返回为空时select中却给出的是上一次的选项值。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值