vue select的change事件,将点击过的城市名存在数组中,下次调用不需要再调用接口

<template>
		<div id="body" class="application" v-show="show" v-cloak>
			<div class="applicationForm">
				<div class="essentialInformation">
					<ul>
						<li>
							<div class="agencyNamjian fr">
								<img src="../assets/img/xiala.png" width="100%" height="100%" />
							</div>
							<div class="agencyName agencyJantou">
                                          <span class="plaseCity" v-show="plaseCityShow" v-text="plaseProvinceText"></span>
							  <select v-model=‘provinceSelect‘ @change ="cityChange(1)">
								<option v-for="(item,index) in application.province" :key="index" :value="item.id" v-text="item.title"></option>
							  </select>
							</div>
						</li>
						<li>
							<div class="agencyNamjian fr">
								<img src="../assets/img/xiala.png" width="100%" height="100%" />
							</div>
							<div class="agencyName agencyJantou">
                                            <span class="plaseCity" v-show="plaseCityShow" v-text="plaseCityText"></span>
								<select v-model="citySelect" @change="cityChange(2)">
                                              <option v-for="(item,index) in city" :key="index" :value="item.id" v-text="item.title"></option>
								</select>
							</div>
						</li>
						<li>
							<div class="agencyNamjian fr ">
								<img src="../assets/img/xiala.png" width="100%" height="100%" />
							</div>
							<div class="agencyName agencyJantou noBorder">
                                            <span class="plaseCity" v-show="plaseCityShow" v-text="plaseCountyText"></span>
								<select v-model="countySelect">
                                              <option v-for="(item,index) in county" :key="index" :value="item.id" v-text="item.title"></option>
								</select>
							</div>
						</li>
					</ul>
				</div>
			</div>
		</div>
  </template>
<script>
  export default {
    name: ‘application‘,
    data () {
      return {
        show: false,
        application: {
          province: [],
          city: {},
          county: {}
        },
        city: [],
        county: [],
        provinceSelect: ‘‘,
        citySelect: ‘‘,
        countySelect: ‘‘,
        tishi: false,
        tishiTxt: ‘‘,
        plaseCityShow: true,
        plaseCityText: ‘请子选择城市‘,
        plaseProvinceText: ‘请选择城市‘,
        plaseCountyText: ‘请选择(区)县‘
      }
    },
    methods: {
      verify: function () {
        let thisObj = this
        this.$chaos.setTitle(‘报名表单‘)
        this.$chaos.verify(function () {
          thisObj.$chaos.ajax({
            data: {
              pid: ‘0‘
            },
            slient: true,
            userinfo: true,
            url: ‘get_address_by_pid‘,
            callback: function (type, res) {
              if (type !== ‘success‘) {
                return
              }
              if (res.status) {
                thisObj.application.province = res.info.region_list
                thisObj.show = true
              } else {
                thisObj.$vux.toast.show({
                  text: res.msg,
                  type: ‘text‘,
                  position: ‘bottom‘
                })
              }
            }
          })
          thisObj.$chaos.ajax({
            slient: true,
            userinfo: true,
            url: ‘user_is_sign‘,
            callback: function (type, res) {
              if (type !== ‘success‘) {
                return
              }
              if (res.status) {
                let userInfo = thisObj.$chaos.getUserInfo()
                if (userInfo.user_info.is_sign === 1) {
                  window.location.href = ‘#/CourseList‘
                } else {
                  userInfo.user_info.is_buy_course = 1
                  thisObj.$chaos.setUserInfo(userInfo)
                }
              } else {
                thisObj.$vux.toast.show({
                  text: res.msg,
                  type: ‘text‘,
                  position: ‘bottom‘
                })
              }
            }
          })
        }, false)
      },
      cityChange: function (type) {
        let thisObj = this
        if (type === 1) {
          if (thisObj.provinceSelect === ‘‘ || typeof thisObj.provinceSelect === ‘undefined‘) {
            return
          }
          if (typeof thisObj.application.city[thisObj.provinceSelect] === ‘undefined‘) {
            thisObj.plaseCityShow = false
            thisObj.$chaos.ajax({
              data: {
                pid: thisObj.provinceSelect
              },
              slient: true,
              userinfo: true,
              url: ‘Attend/get_address_by_pid‘,
              callback: function (type, res) {
                if (type !== ‘success‘) {
                  return
                }
                if (res.status) {
                  thisObj.application.city[thisObj.provinceSelect] = res.info.region_list
                  thisObj.city = res.info.region_list
                  thisObj.citySelect = thisObj.city[0][‘id‘]
                } else {
                  thisObj.$vux.toast.show({
                    text: res.msg,
                    type: ‘text‘,
                    position: ‘bottom‘
                  })
                }
              }
            })
          } else {
            thisObj.city = thisObj.application.city[thisObj.provinceSelect]
            thisObj.citySelect = thisObj.city[0][‘id‘]
          }
        } else {
          if (thisObj.city === ‘‘ || typeof thisObj.city === ‘undefined‘) {
            return
          } else {
            if (typeof thisObj.application.county[thisObj.city] === ‘undefined‘) {
              thisObj.$chaos.ajax({
                data: {
                  pid: thisObj.citySelect
                },
                slient: true,
                userinfo: true,
                url: ‘Attend/get_address_by_pid‘,
                callback: function (type, res) {
                  if (type !== ‘success‘) {
                    return
                  }
                  if (res.status) {
                    thisObj.application.county[thisObj.citySelect] = res.info.region_list
                    thisObj.county = res.info.region_list
                    thisObj.countySelect = thisObj.county[0][‘id‘]
                  } else {
                    thisObj.$vux.toast.show({
                      text: res.msg,
                      type: ‘text‘,
                      position: ‘bottom‘
                    })
                  }
                }
              })
            } else {
              thisObj.county = thisObj.application.county[thisObj.citySelect]
              thisObj.countySelect = thisObj.county[0][‘id‘]
            }
          }
        }
      }
    },
    created: function () {
      this.verify()
    },
    watch: {
      ‘$route‘: ‘verify‘
    }
  }
</script>
<style scoped>
  [v-cloak] {
    display: none;
  }
  .plaseCity{
    position: absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;
    line-height: 55px;
    text-indent: 10px;
  }
  .essentialInformation, .importaInformation {
    background: #FFFFFF;
  }
  .essentialInformation {
    margin: 10px 0;
  }
  .essentialInformation ul, .importaInformation ul {
    margin: 0 15px;
  }
  .agencyNameImg {
    width: 20px;
    height: 20px;
    line-height: 4.3;
  }
  .fl {
    float: left;
  }
  .noBorder {
    border: 0;
  }
  .essentialInformation:after {
    content: ‘‘;
    display: block;
    clear: both;
  }
  .agencyNamjian {
    width: 11px;
    height: 8px;
    line-height: 4.3;
  }
  .agencyJantou {
    padding-right: 40px;
    position: relative;
  }
  .agencyName {
    margin-left: 30px;
    border-bottom: 1px solid #cccccc;
    line-height: 3.8
  }
  .essentialInformation input, .essentialInformation select {
    width: 100%;
    text-indent: 10px;
    border: 0;
    -webkit-appearance: none;
    background: transparent;
  }
  .essentialInformation select {
    height: 55px;
    position: relative;
    z-index: 0;
  }
  .agencyBut {
    margin-top: 100px;
  }
  .squadButton {
    text-align: center;
    color: #fff;
    background: #fbac36;
    margin: 0 30px;
    line-height: 2.5;
    font-size: 16px;
    box-shadow: 0px 1px 5px #ccc;
  }
  .agencyBut {
    margin-top: 100px;
  }

</style>

  

时间: 2024-10-04 21:42:17

vue select的change事件,将点击过的城市名存在数组中,下次调用不需要再调用接口的相关文章

下拉列表select的change事件

select中的option不支持点击click事件,只能通过change事件进行下拉框的事件处理,若需持续触发事件,可采用将value值设为固定值的方法,例如: $(".opbutton").delegate(".deal","change",function(){ var val=$(this).val(); $(this).val('0');//将select设置为固定值不改变 if(val=='collect'){ $(".ad

input框获取焦点和失去焦点,select框change事件

转载:http://www.cnblogs.com/weeky/archive/2012/04/08/2438002.html 以下可以直接调用,注意:jQuery引用用的Google.js> 1 <html xmlns="http://www.w3.org/1999/xhtml"> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charse

jquery 怎么触发select的change事件

可以使用jQuery的trigger() 方法来响应事件 定义和用法 trigger() 方法触发被选元素的指定事件类型. 语法 $(selector).trigger(event,[param1,param2,...]) 参数描述 event    必需.规定指定元素要触发的事件.可以使自定义事件(使用 bind() 函数来附加),或者任何标准事件. [param1,param2,...]    可选.传递到事件处理程序的额外参数.额外的参数对自定义事件特别有用. 实例: 触发 select元

js改变select的选中项不触发select的change事件

// test var selectEl = document.querySelector('select') var buttonEl = document.querySelector('button') selectEl.addEventListener('change', function() { console.log(this.value) }) buttonEl.addEventListener('click', function() { selectEl.options[1].se

select控件自动触发change事件

这里接上面的二级联动.背景:当页面跳转到修改页面时,需要首先绑定学院和专业.这就需要在页面加载时触发select的change事件,具体用trigger函数进行实现.代码如下. $("#xsxy").change(function (event, flag) { var xyidvalue; if (flag == "start") xyidvalue = '<%=xsxyid%>'; else xyidvalue = $(this).val(); $.

复选框 省市区 联动(监听input的change事件)

需求:省市区三级包含复选框按钮以及文字描述.点击文字显示对应的下级地区,点击复选框选择对应的下级区域勾选. 分析:监听input的change事件当点击复选框省  选择对应的第一个市区,同时默认选中第三级区域的第一个.同理监听span或者label(因为label与input的搭配使用) 辅助:后台提供省市区的数据: 两种方式: A:后台直接给dom结构(后台写好基本构架,前段自己在后台code填写需要的dom,class,方便前端开发) B:后台直接给前段一个json数据,前段自己遍历.(和后

element-ui 点击编辑弹出dialog组件中select组件绑定值改变,但是不触发change事件

代码结构如下: 现象视频如下: 现象原因:经过排查发现 此时点击操作不触发chang事件,后台响应数据中没有订单取消原因orderCanleRemark字段,此时导致不触发change事件, 解决方案:方案1,:让后台配合响应该字段,无论是否为空都响应该字段 方案2:在后台响应数据赋值给,this.form之前,手动添加该字段到后台响应数据中 代码如下: 原文地址:https://www.cnblogs.com/liujiazhu/p/8649810.html

easyui给select控件绑定change事件

一般的做法是使用jQuery来绑定,例如: $("#id").change(function(){ alert("change事件绑定"); }); 当给select加上class="easyui-combobox"这样的样式后,上面的绑定方式失效不相应,正确的方式如下: <select required="false" class="easyui combobox"name="city&q

点击事件里面的change事件,多次触发change事件

最近做个项目,在点击按钮后弹出一个层,里面有单选按钮,选中单选按钮时就可以动态添加到对应的地方了 $(".xinz").click(function(event){ event.stopPropagation(); radioBoxChange += 1; //clickChange = "shspClick"; var radioBox=$("#radioBox"); var hsBox=$(this).siblings(".deli