vue.js

关注公众号 jb51net

关闭
首页 > 网络编程 > JavaScript > javascript类库 > vue.js > vant的Cascader级联选择组建css样式错乱

解决vant的Cascader级联选择组建css样式错乱问题

作者:橙-极纪元JJY.Cheng

这篇文章主要介绍了解决vant的Cascader级联选择组建css样式错乱问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教

未修复的效果

修复后的效果

修复需要的css代码

/*级联控件 start*/
 
.cplvfx .van-popup {
  position: fixed;
  max-height: 100%;
  overflow-y: auto;
  background-color: #fff;
  -webkit-transition: -webkit-transform 0.3s;
  transition: -webkit-transform 0.3s;
  transition: transform 0.3s;
  transition: transform 0.3s, -webkit-transform 0.3s;
  -webkit-overflow-scrolling: touch;
}
 .cplvfx .van-popup--center {
  top: 50%;
  left: 50%;
  -webkit-transform: translate3d(-50%, -50%, 0);
          transform: translate3d(-50%, -50%, 0);
}
 .cplvfx .van-popup--center.van-popup--round {
  border-radius: 16px;
}
 .cplvfx .van-popup--top {
  top: 0;
  left: 0;
  width: 100%;
}
 .cplvfx .van-popup--top.van-popup--round {
  border-radius: 0 0 16px 16px;
}
 .cplvfx .van-popup--right {
  top: 50%;
  right: 0;
  -webkit-transform: translate3d(0, -50%, 0);
          transform: translate3d(0, -50%, 0);
}
 .cplvfx .van-popup--right.van-popup--round {
  border-radius: 16px 0 0 16px;
}
 .cplvfx .van-popup--bottom {
  bottom: 0;
  left: 0;
  width: 100%;
}
 .cplvfx .van-popup--bottom.van-popup--round {
  border-radius: 16px 16px 0 0;
}
 .cplvfx .van-popup--left {
  top: 50%;
  left: 0;
  -webkit-transform: translate3d(0, -50%, 0);
          transform: translate3d(0, -50%, 0);
}
 .cplvfx .van-popup--left.van-popup--round {
  border-radius: 0 16px 16px 0;
}
 .cplvfx .van-popup--safe-area-inset-bottom {
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
}
 .cplvfx .van-popup-slide-top-enter-active,
 .cplvfx .van-popup-slide-left-enter-active,
 .cplvfx .van-popup-slide-right-enter-active,
 .cplvfx .van-popup-slide-bottom-enter-active {
  -webkit-transition-timing-function: ease-out;
          transition-timing-function: ease-out;
}
 .cplvfx .van-popup-slide-top-leave-active,
 .cplvfx .van-popup-slide-left-leave-active,
 .cplvfx .van-popup-slide-right-leave-active,
 .cplvfx .van-popup-slide-bottom-leave-active {
  -webkit-transition-timing-function: ease-in;
          transition-timing-function: ease-in;
}
 .cplvfx .van-popup-slide-top-enter,
 .cplvfx .van-popup-slide-top-leave-active {
  -webkit-transform: translate3d(0, -100%, 0);
          transform: translate3d(0, -100%, 0);
}
 .cplvfx .van-popup-slide-right-enter,
 .cplvfx .van-popup-slide-right-leave-active {
  -webkit-transform: translate3d(100%, -50%, 0);
          transform: translate3d(100%, -50%, 0);
}
 .cplvfx .van-popup-slide-bottom-enter,
 .cplvfx .van-popup-slide-bottom-leave-active {
  -webkit-transform: translate3d(0, 100%, 0);
          transform: translate3d(0, 100%, 0);
}
 .cplvfx .van-popup-slide-left-enter,
 .cplvfx .van-popup-slide-left-leave-active {
  -webkit-transform: translate3d(-100%, -50%, 0);
          transform: translate3d(-100%, -50%, 0);
}
 .cplvfx .van-popup__close-icon {
  position: absolute;
  z-index: 1;
  color: #c8c9cc;
  font-size: 22px;
  cursor: pointer;
}
 .cplvfx .van-popup__close-icon:active {
  color: #969799;
}
 .cplvfx .van-popup__close-icon--top-left {
  top: 16px;
  left: 16px;
}
 .cplvfx .van-popup__close-icon--top-right {
  top: 16px;
  right: 16px;
}
 .cplvfx .van-popup__close-icon--bottom-left {
  bottom: 16px;
  left: 16px;
}
 .cplvfx .van-popup__close-icon--bottom-right {
  right: 16px;
  bottom: 16px;
}
 
.cplvfx .van-calendar__popup.van-popup--top,
.cplvfx .van-calendar__popup.van-popup--bottom {
  height: 80%;
}
.cplvfx .van-calendar__popup.van-popup--left,
.cplvfx .van-calendar__popup.van-popup--right {
  height: 100%;
}
.cplvfx .van-calendar__popup .van-popup__close-icon {
  top: 11px;
}
 
.cplvfx .demo-contact-card .van-popup {
  height: 100%;
  background-color: #f7f8fa;
}
 
 
 
.cplvfx .van-cascader__header {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
          align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
          justify-content: space-between;
  height: 48px;
  padding: 0 16px;
}
.cplvfx .van-cascader__title {
  font-weight: 500;
  font-size: 16px;
  line-height: 20px;
}
.cplvfx .van-cascader__close-icon {
  color: #c8c9cc;
  font-size: 22px;
}
.cplvfx .van-cascader__close-icon:active {
  color: #969799;
}
.cplvfx .van-cascader__tabs .van-tab {
  -webkit-box-flex: 0;
  -webkit-flex: none;
          flex: none;
  padding: 0 10px;
}
.cplvfx .van-cascader__tabs.van-tabs--line .van-tabs__wrap {
  height: 48px;
}
.cplvfx .van-cascader__tabs .van-tabs__nav--complete {
  padding-right: 6px;
  padding-left: 6px;
}
.cplvfx .van-cascader__tab {
  color: #323233;
  font-weight: 500;
}
.cplvfx .van-cascader__tab--unselected {
  color: #969799;
  font-weight: normal;
}
.cplvfx .van-cascader__option {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-box-align: center;
  -webkit-align-items: center;
          align-items: center;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
          justify-content: space-between;
  padding: 10px 16px;
  font-size: 14px;
  line-height: 20px;
}
.cplvfx .van-cascader__option:active {
  background-color: #f2f3f5;
}
.cplvfx .van-cascader__option--selected {
  color: #ee0a24;
  font-weight: 500;
}
.cplvfx .van-cascader__selected-icon {
  font-size: 18px;
}
.cplvfx .van-cascader__options {
  box-sizing: border-box;
  height: 384px;
  padding-top: 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
/*级联控件 end*/

html代码

注意:父容器需要加 <div class="cplvfx">

<div class="cplvfx">
  <van-field
  v-model="AddVal"
  is-link
  readonly
  placeholder="请选择活动地区"
  @click="SelectAddStatus = true"
  />
 
  <van-popup v-model="SelectAddStatus" round position="bottom">
	  <van-cascader
	  v-model="SelectAddVal"
	  title="请选择所在地区"
	  :options="AreaData"
	  active-color="#17BF8C"
	  @close="SelectAddStatus = false"
	  @change="AddSelectChange"
	  @finish="AddSelectFinish"
	  />
  </van-popup>
</div>

js 代码

一、引入必要组建

import { Popup } from 'vant';
import { Cascader } from 'vant';
import { Field } from 'vant';
 
Vue.use(Popup);
Vue.use(Cascader);
Vue.use(Field);

二、参数

export default {
data(){
  return{
   SelectAddStatus:false,//地址选择状态
   SelectAddVal:'',//地址值
   AddVal:'',//地址值
  }
},
created:(){},
methods:{
    //地址选择发生变化
    AddSelectChange({ value, selectedOptions, tabIndex }){
      console.log('地址选择发生变化');
      console.log(value);
      console.log(selectedOptions);
      console.log(tabIndex);
    },
    //地址选择完成
    AddSelectFinish({ value, selectedOptions, tabIndex }){
      console.log('地址选择完成');
      console.log(value);
      console.log(selectedOptions);
      console.log(tabIndex);
      this.SelectAddStatus = false;
      this.AddVal = selectedOptions.map((option) => option.text).join('/');
      console.log('this.SelectAddVal===');
      console.log(this.SelectAddVal);
      console.log('this.AddVal===');
      console.log(this.AddVal );
    }
 
},
}

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文