最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue+Ant?Design進(jìn)度條滑塊與input聯(lián)動效果實現(xiàn)

 更新時間:2022年12月07日 15:16:19   作者:周家大小姐.  
最近接到這樣一個需求滑塊進(jìn)度與輸入框為一致,默認(rèn)值為80,最小不能小于30,最大為100,怎么實現(xiàn)這個聯(lián)動效果呢,下面小編給大家分享下基于vue+Ant?Design進(jìn)度條滑塊與input聯(lián)動效果的實現(xiàn),感興趣的朋友跟隨小編一起看看吧

 需求:滑塊進(jìn)度與輸入框為一致,默認(rèn)值為80,最小不能小于30,最大為100

 子組件:

<template>
  <div class="progress-box">
    <div
      ref="slider"
      class="slider"
    >
      <div
        class="process"
        :style="{ width }"
      ></div>
      <div
        ref="trunk"
        class="thunk"
        :style="{ left }"
      >
        <div class="block"></div>
      </div>
    </div>
    <div>
      <a-input-number
        v-model="per"
        class="input-num"
        :min="inputMin"
        :max="inputMax"
        @change="handleChangeNum"
      />
    </div>
  </div>
</template>
<script>
export default {
  props: {
    sliderMin: { // 最小值
      type: Number,
      default: 0
    },
    sliderMax: { // 進(jìn)度條最大值
      type: Number,
      default: 0
    },
    value: { // 對當(dāng)前值進(jìn)行雙向綁定實時顯示拖拽進(jìn)度
      type: Number,
      default: 0
    },
    inputMin: {
      type: Number,
      default: 0
    },
    inputMax: {
      type: Number,
      default: 100
    }
  },
  data() {
    return {
      slider: null, // 滾動條DOM元素
      thunk: null, // 拖拽DOM元素
      per: Math.max(this.sliderMin, this.value) // 當(dāng)前值
    }
  },
  computed: {
    // 設(shè)置一個百分比,提供計算slider進(jìn)度寬度和trunk的left值
    scale() { // 百分比
      return this.per / this.sliderMax
    },
    width() {
      if (this.slider) { // 設(shè)置進(jìn)度激活的寬度
        return (this.slider.offsetWidth * this.scale) + 'px'
      } else {
        return 0 + 'px'
      }
    },
    left() { // trunk left = slider進(jìn)度width + trunk寬度/2
      if (this.slider) { // 設(shè)置圓點所在的位置
        return (this.slider.offsetWidth * this.scale) - this.thunk.offsetWidth / 2 + 'px'
      } else {
        return 0 + 'px'
      }
    }
  },
  // 渲染到頁面的時候
  mounted() {
    this.slider = this.$refs.slider
    this.thunk = this.$refs.trunk
    const _this = this
    this.thunk.onmousedown = function(e) {
      const width = parseInt(_this.width)
      const disX = e.clientX
      document.onmousemove = function(e) {
        // 拖拽的時候獲取的新width
        const newWidth = (e.clientX - disX + width)
        // 拖拽的時候得到新的百分比
        const scale = newWidth / _this.slider.offsetWidth
        _this.per = Math.ceil((_this.sliderMax) * scale)// 對一個數(shù)進(jìn)行上取整把小數(shù)轉(zhuǎn)為整數(shù)(0.3=>30)
        _this.per = Math.max(_this.per, _this.sliderMin)
        _this.per = Math.min(_this.per, _this.sliderMax)
        _this.$emit('input', _this.per)
      }
      document.onmouseup = function() {
        document.onmousemove = document.onmouseup = null
      }
      return false
    }
  },
  methods: {
    handleChangeNum(e) {
      this.per = e
    }
  }
}
</script>
<style lang="scss" scoped>
.progress-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
.clear:after {
  content: '';
  display: block;
  clear: both;
}
.slider {
  user-select: none;
  position: relative;
  width: calc(100% - 104px);
  height: 4px;
  background: #f5f5f5;
  border-radius: 5px;
  cursor: pointer;
  .process {
    position: absolute;
    left: 0;
    top: 0;
    width: 112px;
    height: 6px;
    border-radius: 5px;
    background: #3296fa;
  }
  .thunk {
    position: absolute;
    left: 100px;
    top: -5px;
    width: 14px;
    height: 14px;
  }
  .block {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #3296fa;
    background: rgba(255, 255, 255, 1);
    transition: 0.2s all;
  }
}
</style>

父組件使用

  <div class="xk-control-item">
      <div class="xk-item-title">
          <span>相似度(≥)</span>
       </div>
       <div class="xk-item-value">
           <c-progress
            v-model="per"
            :sliderMin="30"
            :sliderMax="100"
            :inputMin='30'
              />
        </div>
   </div>
 
<script>
import CProgress from '@/components/CProgress'
export default {
  name: 'VisitorTrack',
  components: {
    CProgress
  },
  data() {
    return {
    }
  },
  computed: {
    per: {
      get() {
        return 80
      },
      set(val) {
        // console.log(val)
      }
    }
  },
  watch: {
 
  },
  methods: {
 
   
  }
 
}
</script>

補(bǔ)充知識

ant-design-vue 動態(tài)添加input行及動態(tài)校驗

這里涉及到動態(tài)input表單校驗 我僅給自己記錄一下

<!-- 動態(tài)添加行 -->
   <a-form-model-item
       :wrapper-col="newWrapper"
       style="padding-left:63px;padding-right:40px;"
       v-for="(item, index) in form.information"
       :key="item.key"
       >
       <a-form-model-item class="fl" :prop="'information.' + index + '.name'"
       :rules="{
           required: true,
           message: '店鋪名不能為空',
           trigger: ['blur','change'],
       }">
           <a-input
               v-model.trim="form.information[index].name"
               placeholder="請輸入店鋪名稱"
               style="margin-right: 1%"
           />
       </a-form-model-item>
       <a-form-model-item class="fl" :prop="'information.' + index + '.address'"
       :rules="{
           required: true,
           message: '店鋪地址不能為空',
           trigger: ['blur','change'],
       }">
           <a-input
               v-model.trim="form.information[index].address"
               placeholder="請輸入店鋪地址"
               style="margin-right: 1%"
           />
       </a-form-model-item>
       <a-form-model-item class="fl" :prop="'information.' + index + '.storeManagerName'"
       :rules="{
           required: true,
           message: '店長姓名不能為空',
           trigger: ['blur','change'],
       }">
           <a-input
               v-model.trim="form.information[index].storeManagerName"
               placeholder="請輸入店長姓名"
               style="margin-right: 1%"
           />
       </a-form-model-item>
       <a-form-model-item class="fl" style="margin-right: 3%;" :prop="'information.' + index + '.storeManagerPhone'"
       :rules="[{required: true,message: '店長手機(jī)不能為空',trigger: ['blur','change']},
               {validator: mobilephoneValidate,trigger: ['blur','change'] }]"          
       >
           <a-input
               v-model.trim="form.information[index].storeManagerPhone"
               placeholder="請輸入店長手機(jī)號"
           />
       </a-form-model-item>
       <a
       v-if="form.information.length > 1"
       :disabled="form.information.length === 1"
       @click="removeRows(item)"
       >刪除</a>
   </a-form-model-item>

添加 刪除的方法

// 動態(tài)刪除添加輸入行
        removeRows(item) {
            let index = this.form.information.indexOf(item);
            if (index !== -1) {
                this.form.information.splice(index, 1);
            }
        },
        addRows() {
            this.form.information.push({
                name: '',
                address: '',
                storeManagerName: '',
                storeManagerPhone: '',
                key: Date.now(),
            });
        },

手機(jī)號或者其他單獨的表單校驗寫在methods里

// 動態(tài)添加行 店長手機(jī)號驗證
        testMobilephone: function (str) {
            const regex = /^1[3456789]\d{9}$/
            if (!regex.test(str)) {
            return false
            } else {
            return true
            }
        },
        mobilephoneValidate (rule, value, callback) {
        // 主要就是添加一個對undefined和空串的判斷
        if (typeof (value) === 'undefined' || value === '') {
            callback()
            } else {
                if (!this.testMobilephone(value)) {
                callback(new Error('請輸入正確手機(jī)格式'))
                }
                callback()
            }
        },

這里information數(shù)組 在data里寫上一組空對象 是為了保證有一組input行顯示出來 不寫input行則會隱藏掉

里插入圖片描述

到此這篇關(guān)于vue+Ant Design進(jìn)度條滑塊與input聯(lián)動的文章就介紹到這了,更多相關(guān)vue+Ant Design進(jìn)度條滑塊內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 遇到vue前端npm?i報錯多個版本不一致問題及解決

    遇到vue前端npm?i報錯多個版本不一致問題及解決

    這篇文章主要介紹了遇到vue前端npm?i報錯多個版本不一致問題及解決,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • Nuxt的路由動畫效果案例

    Nuxt的路由動畫效果案例

    這篇文章主要介紹了Nuxt的路由動畫效果案例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • vue 對象添加或刪除成員時無法實時更新的解決方法

    vue 對象添加或刪除成員時無法實時更新的解決方法

    這篇文章主要介紹了vue 對象添加或刪除成員時無法實時更新的解決方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-05-05
  • vue3中element-plus表格搜索過濾數(shù)據(jù)

    vue3中element-plus表格搜索過濾數(shù)據(jù)

    本文主要介紹了vue3中element-plus表格搜索過濾數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2025-03-03
  • Vue.js實現(xiàn)雙向數(shù)據(jù)綁定方法(表單自動賦值、表單自動取值)

    Vue.js實現(xiàn)雙向數(shù)據(jù)綁定方法(表單自動賦值、表單自動取值)

    今天小編就為大家分享一篇Vue.js實現(xiàn)雙向數(shù)據(jù)綁定方法(表單自動賦值、表單自動取值),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 關(guān)于vue-router的那些事兒

    關(guān)于vue-router的那些事兒

    要學(xué)習(xí)vue-router就要先知道這里的路由是什么?為什么我們不能像原來一樣直接用標(biāo)簽編寫鏈接哪?vue-router如何使用?常見路由操作有哪些?等等這些問題,就是本篇要探討的主要問題,感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧
    2018-05-05
  • vue項目的屏幕自適應(yīng)多個方案總結(jié)

    vue項目的屏幕自適應(yīng)多個方案總結(jié)

    最近在用VUE寫大屏頁面,遇到屏幕自適應(yīng)問題,下面這篇文章主要給大家介紹了關(guān)于vue項目的屏幕自適應(yīng)多個方案的相關(guān)資料,文中通過實例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • vue3中實現(xiàn)雙向數(shù)據(jù)綁定的方法

    vue3中實現(xiàn)雙向數(shù)據(jù)綁定的方法

    Vue3中,雙向數(shù)據(jù)綁定主要通過v-model指令實現(xiàn),v-model是一個語法糖,結(jié)合了v-bind和v-on指令來實現(xiàn)數(shù)據(jù)的雙向綁定,它在內(nèi)部做了綁定數(shù)據(jù)和監(jiān)聽輸入事件兩件事,感興趣的朋友跟隨小編一起看看吧
    2024-12-12
  • 編寫 Vue v-for 循環(huán)的 7 種方式

    編寫 Vue v-for 循環(huán)的 7 種方式

    這篇文章主要分享可編寫 Vue v-for 循環(huán)的 7 種方式,在Vue中,基本上每個項目都會用到v-for循環(huán)。它們允許你在模板代碼中編寫for循環(huán),接下來一起看看下面文章的詳細(xì)介紹吧

    2021-12-12
  • Vue動畫之第三方類庫實現(xiàn)動畫方式

    Vue動畫之第三方類庫實現(xiàn)動畫方式

    這篇文章主要介紹了Vue動畫之第三方類庫實現(xiàn)動畫方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-04-04

最新評論

易门县| 哈尔滨市| 平昌县| 成都市| 桃源县| 佛山市| 高陵县| 鹤峰县| 行唐县| 宜黄县| 长春市| 宁德市| 金门县| 灵武市| 正镶白旗| 柳江县| 昔阳县| 宝兴县| 新密市| 榆树市| 萨嘎县| 麻江县| 容城县| 高淳县| 嘉黎县| 嵊泗县| 黄大仙区| 柳州市| 河曲县| 贵港市| 滨州市| 华坪县| 犍为县| 苗栗县| 绥宁县| 双桥区| 华坪县| 屯昌县| 隆安县| 革吉县| 信宜市|