亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue?實現(xiàn)滑動塊解鎖示例詳解

 更新時間:2022年08月19日 15:35:11   作者:一起去看星星吧  
這篇文章主要為大家介紹了vue?實現(xiàn)滑動塊解鎖示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

引言

從0開始,寫一個登錄滑動解鎖的功能。

首先,新創(chuàng)建一個 vue 項目。 或者在已有的項目寫也可以。 將無用的代碼刪一下。

下載需要用到的組件庫

1、下載 element-ui。

yarn add  element-ui -S   or   npm i element-ui -S

2、 在main.js 中引入。

    import Vue from 'vue'
    import App from './App.vue'
    import router from './router'
    import store from './store'
+  import ElementUI from 'element-ui'  
+  import 'element-ui/lib/theme-chalk/index.css'
    Vue.config.productionTip = false
+  Vue.use(ElementUI)
    new Vue({
      router,
      store,
 +   el: '#app',
      render: h => h(App)
    }).$mount('#app')

3、測試是否下載成功。

<template>
  <div class="about">
  +   <el-button type="primary">主要按鈕</el-button>
    <h1>This is an about page</h1>
  </div>
</template>

書寫登錄頁面

頁面可以正常展示按鈕,說明下載成功??梢蚤_始寫代碼了。

寫一個簡單的登錄頁面。

Login.vue

template 結(jié)構(gòu):

<template>
  <div class="login-container">
    <div class="login-header">
      <h1>xxx系統(tǒng)</h1>
    </div>
   <div class="login-body">
      <div class="login-form-container">
        <el-form
          ref="loginFormRef"
          class="form-style"
          :label-position="`right`"
          :model="loginFormData"
          status-icon
        >
          <el-form-item
            name="username"
            prop="username"
            >
            <el-input
              v-model="loginFormData.username"
              placeholder="請輸入用戶名"
              prefix-icon="el-icon-user"
              clearable
            />
          </el-form-item>
          <el-form-item
            class="el-item-style"
            name="password"
            prop="password"
          >
            <!-- 密碼框 -->
            <el-input
              prefix-icon="el-icon-lock"
              v-model="loginFormData.password"
              :type="`${hasOpenEye? 'text':'password'}`"
              placeholder="請輸入密碼">
              <i
                slot="suffix"
                :class="[hasOpenEye ? 'el-icon-unlock' : 'el-icon-lock']"
                style="font-size: 14px; cursor: pointer"
                @click="hasOpenEye = !hasOpenEye"/>
            </el-input>
          </el-form-item>
          <el-form-item class="el-item-style">
            <el-button
              :loading="false"
              style="
                width: 100%;
                height: 46px;
                line-height: 15px;
                font-size: 23px;
              "
              type="primary"
              @click="login"
            >登錄</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

script 邏輯:

<script>
export default {
  // 登錄表單數(shù)據(jù)
  data () {
  return {
    loginFormData: {
      username: "123232",
      password: "21232"
    },
    hasOpenEye : false, // 是否顯示密碼
  }
  },
  components: {},
  methods: {
    login () {},
  },
}
</script>

style 樣式:

<style lang="less" scoped>
.login-container {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  user-select: none;
  flex-direction: column;
  .login-header {
    display: flex;
    align-items: center;
    padding-left: 50px;
    cursor: pointer;
  }
  .login-footer {
    display: flex;
    justify-content: center;
    align-items: center;
    color: #322b34;
    font-size: 12px;
  }
  .login-header,
  .login-footer {
    height: 10%;
  }
  .login-body {
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 100% auto;
    flex: 1 1;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    user-select: none;
    .login-form-container {
      width: 30%;
      border: 1px solid mix(pink, #000, 80);
      box-shadow: 0 0.5em 1em rgba(0, 0, 0, 0.3);
      background: linear-gradient(
        to bottom,
        rgba(255, 255, 255, 0.3),
        rgba(0, 0, 0, 0.3)
      );
      padding: 20px 30px;
      border-radius: 5px;
    }
  }
}
</style>

登錄頁面效果展示:

寫滑動解鎖組件

1、下載安裝包:

vue-monoplasty-slide-verify

2、導(dǎo)入到 main.js 中

import SlideVerify from 'vue-monoplasty-slide-verify';
Vue.use(SlideVerify);

3、新建一個文件component / verify.vue

template 模板:

<template>
  <div>
    <!-- title="滑塊驗證碼" -->
    <el-dialog
      :visible.sync="dialogVisible"
      :before-close="dialogBeforeClose"
      :close-on-click-modal="false"
    >
      <div class="flex">
        <slide-verify
          ref="slideblock"
          :w="fullWidth"
          :h="fullHeight"
          :accuracy="accuracy"
          :slider-text="text"
          :imgs="imgList"
          @again="onAgain"
          @fulfilled="onFulfilled"
          @success="onSuccess"
          @fail="onFail"
          @refresh="onRefresh"
        />
      </div>
    </el-dialog>
  </div>
</template>

script 代碼:

<script>
export default {
  name: 'verify',
  data() {
    return {
      dialogVisible: false,
      fullWidth: 450,
      fullHeight: 304,
      msg: '',
      text: '請向右滑動滑塊完成驗證',
      // 精確度小,可允許的誤差范圍??;為1時,則表示滑塊要與凹槽完全重疊,才能驗證成功。默認(rèn)值為5
      accuracy: 3,
      imgList: [
      // 圖片的路徑:
        require('../assets/3.jpg')
      ]
    }
  },
  mounted() {},
  methods: {
    dialogBeforeClose() {
      this.dialogVisible = false
    },
    onSuccess() {
      console.log('驗證通過')
      this.msg = 'login success'
      this.dialogVisible = false
      this.$emit('verifySuccess')
       this.$message.success("驗證成功")
       this.$router.push('/a')
    },
    onFail() {
      console.log('驗證不通過')
      this.msg = '驗證不通過'
        this.$message.error('驗證失敗')
    },
    onRefresh() {
      console.log('點擊了刷新小圖標(biāo)')
      this.msg = ''
    },
    onFulfilled() {
      console.log('刷新成功啦!')
    },
    onAgain() {
      console.log('檢測到非人為操作的哦!')
      this.msg = 'try again'
      // 刷新
      this.$refs.slideblock.reset()
    },
    handleClick() {
      // 父組件直接可以調(diào)用刷新方法
      this.$refs.slideblock.reset()
      console.log(23333);
    }
  }
}
</script>

style 樣式:

<style lang="less" scoped>
.flex{
  display: flex;
  align-items: center;
  justify-content: center;
}
/deep/ .el-dialog {
  width: 500px;
  border-radius: 16px;
  margin: auto;
}
/deep/ .el-dialog__header {
  display: none;
}
/deep/ .slide-verify-slider {
  border-radius: 33px;
}
/deep/ .slide-verify-slider-mask {
  border-radius: 33px 0 0 33px;
}
</style>

將滑動組件運用到我們的 Login 組件中:

import verify from "../components/verify.vue";
export default {
 components: {
    verify
  },
}
<template>
   <el-form>
   ......
   </el-form>
+ <verify ref="verify"></verify>
</template>

補充邏輯代碼

login () {
      this.$refs.verify.dialogVisible = true
  },

最終效果:

完成。

以上就是vue 實現(xiàn)滑動塊解鎖示例詳解的詳細內(nèi)容,更多關(guān)于vue 滑動塊解鎖的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • import.meta.glob() 如何導(dǎo)入多個目錄下的資源(最新推薦)

    import.meta.glob() 如何導(dǎo)入多個目錄下的資源(最新推薦)

    import.meta.glob() 其實不僅能接收一個字符串,還可以接收一個字符串?dāng)?shù)組,就是匹配多個位置,本文給大家介紹import.meta.glob() 如何導(dǎo)入多個目錄下的資源,感興趣的朋友一起看看吧
    2023-11-11
  • elementui時間/日期選擇器選擇禁用當(dāng)前之前(之后)時間代碼實例

    elementui時間/日期選擇器選擇禁用當(dāng)前之前(之后)時間代碼實例

    當(dāng)我們在進行網(wǎng)頁開發(fā)時,通常需要用到一些日期組件來方便用戶選擇時間,其中element日期組件是一個非常好用的工具,這篇文章主要給大家介紹了關(guān)于elementui時間/日期選擇器選擇禁用當(dāng)前之前(之后)時間的相關(guān)資料,需要的朋友可以參考下
    2024-02-02
  • Vue之解決Echarts組件使用ID不能復(fù)用的問題

    Vue之解決Echarts組件使用ID不能復(fù)用的問題

    這篇文章主要介紹了Vue之解決Echarts組件使用ID不能復(fù)用的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-03-03
  • Vue大屏數(shù)據(jù)展示示例

    Vue大屏數(shù)據(jù)展示示例

    公司的大數(shù)據(jù)工作組就需要通過數(shù)據(jù)大屏展示一些處理過后有價值的信息,本文主要介紹了Vue大屏數(shù)據(jù)展示示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • vue實踐---根據(jù)不同環(huán)境,自動轉(zhuǎn)換請求的url地址操作

    vue實踐---根據(jù)不同環(huán)境,自動轉(zhuǎn)換請求的url地址操作

    這篇文章主要介紹了vue實踐---根據(jù)不同環(huán)境,自動轉(zhuǎn)換請求的url地址操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-09-09
  • vue3+vite:src使用require動態(tài)導(dǎo)入圖片報錯的最新解決方法

    vue3+vite:src使用require動態(tài)導(dǎo)入圖片報錯的最新解決方法

    這篇文章主要介紹了vue3+vite:src使用require動態(tài)導(dǎo)入圖片報錯和解決方法,本文給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-04-04
  • vue項目中如何調(diào)用多個不同的ip接口

    vue項目中如何調(diào)用多個不同的ip接口

    這篇文章主要介紹了vue項目中如何調(diào)用多個不同的ip接口,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue實現(xiàn)可增刪查改的成績單

    vue實現(xiàn)可增刪查改的成績單

    這篇文章主要為大家詳細介紹了vue實現(xiàn)可增刪查改的成績單,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-10-10
  • vuex的簡單使用教程

    vuex的簡單使用教程

    vuex是一個專門為vue.js設(shè)計的集中式狀態(tài)管理架構(gòu)。這篇文章主要介紹了vuex的簡單使用,需要的朋友可以參考下
    2018-02-02
  • 對vue事件的延遲執(zhí)行實例講解

    對vue事件的延遲執(zhí)行實例講解

    今天小編就為大家分享一篇對vue事件的延遲執(zhí)行實例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08

最新評論