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

vue2和elementUI?實(shí)現(xiàn)落日余暉登錄頁(yè)和滑塊校驗(yàn)功能

 更新時(shí)間:2023年06月05日 09:26:20   作者:碼農(nóng)桃子  
這篇文章主要介紹了vue2和elementUI打造落日余暉登錄頁(yè)和滑塊校驗(yàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

前言

標(biāo)題很夸張,實(shí)則是AI的功能,今天咱也搞一個(gè)登錄頁(yè),其實(shí)滿(mǎn)簡(jiǎn)單的一個(gè)東東,大家也都會(huì)用到,本次僅限前端,沒(méi)有任何后臺(tái)交互,技術(shù)vue、vue-router、element-ui,因?yàn)楸尘皥D是落日,所以就叫它落日余暉登錄頁(yè)

1 項(xiàng)目搭建

使用指令直接構(gòu)建的,選擇vue2版本

vue create login-admin

構(gòu)建后的項(xiàng)目,刪掉了原始的helloworld組件,最終目標(biāo)結(jié)構(gòu)如下:

2 依賴(lài)引入

npm install element-ui
npm install vue-router@3

由于項(xiàng)目是基于vue2的,故vue-router不能使用4.x版本,后面會(huì)有問(wèn)題,在文末說(shuō)了。

3 項(xiàng)目調(diào)整

項(xiàng)目構(gòu)建成功后,刪掉最初的helloworld組件

①vue-router

新建router/index.js文件,將我們要寫(xiě)的登錄頁(yè)路徑放進(jìn)去

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)
const routes = [
    {
        path: '/',
        name: 'Login',
        component: () => import('@/views/login.vue'),
    }
]
const router = new VueRouter({
    routes
})
export default router;

② App.vue

移除掉老的App.vue中的全部?jī)?nèi)容,然后我寫(xiě)一個(gè)簡(jiǎn)單的router-view,讓他來(lái)展示我們的login頁(yè)面

<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>
<script>
</script>
<style>
body {
  margin: 0px;
}
</style>

這里面的body,由于下面有小坑,所以先給margin清空了

③ main.js

簡(jiǎn)單調(diào)整,將我們寫(xiě)的router引進(jìn)來(lái),以及element-ui導(dǎo)入進(jìn)來(lái)

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

4 寫(xiě)登錄頁(yè)

新建頁(yè)面views/login.vue這就是我們的核心頁(yè)面,需要跟上面router中寫(xiě)的路徑保持一致,太長(zhǎng)了,我就簡(jiǎn)單復(fù)制一下

<template>
  <div class="background">
    <el-form
      :rules="rules"
      ref="loginForm"
      :model="loginForm"
      class="loginContainer"
    >
      <h3 class="loginTitle">系統(tǒng)登錄</h3>
      <el-form-item prop="username">
        <el-input
          type="text"
           prefix-icon="el-icon-user"
          v-model="loginForm.username"
          placeholder="請(qǐng)輸入用戶(hù)名"
        >
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          type="password"
           prefix-icon="el-icon-link"
          v-model="loginForm.password"
          placeholder="請(qǐng)輸入密碼"
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <SilderVerify ref="verify"></SilderVerify>
      </el-form-item>
      <el-checkbox v-model="checked" class="loginRemember">記住我</el-checkbox>
      <el-button type="primary" style="width: 100%" @click="submitLogin"
        >登錄</el-button
      >
    </el-form>
  </div>
</template>

然后,換上我落日余暉的背景,逼格一下就上來(lái)了

.background {
  position: absolute;
  background-image: url("../assets/bg.jpg");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  height: 100vh; 
  width: 100%;
}

5 寫(xiě)滑塊校驗(yàn)

這里直接給他封裝成組件了,來(lái)自chatgpt的大力支持,新建文件 components/SilderVerify/index.vue,代碼搞進(jìn)去,太長(zhǎng)了,我就簡(jiǎn)單復(fù)制一下

<template>
  <div class="drag" ref="dragDiv">
    <div class="drag_bg"></div>
    <div class="drag_text">{{ confirmWords }}</div>
    <div
      ref="moveDiv"
      @mousedown="mouseDownFn($event)"
      :class="{ handler_ok_bg: confirmSuccess }"
      class="handler handler_bg"
      style="position: absolute; top: 0px; left: 0px"
    ></div>
  </div>
</template>
<script>
export default {
  name: "SilderVerify",
  data() {
    return {
      beginClientX: 0 /*距離屏幕左端距離*/,
      mouseMoveState: false /*觸發(fā)拖動(dòng)狀態(tài)  判斷*/,
      maxWidth: "" /*拖動(dòng)最大寬度,依據(jù)滑塊寬度算出來(lái)的*/,
      confirmWords: "向右拖動(dòng)滑塊驗(yàn)證" /*滑塊文字*/,
      confirmSuccess: false /*驗(yàn)證成功判斷*/,
    };
  },
  methods: {
    //mousedown 事件
    mouseDownFn: function (e) {
        console.log('mouseDownFn' + e.clientX)
      if (!this.confirmSuccess) {
        e.preventDefault && e.preventDefault(); //阻止文字選中等 瀏覽器默認(rèn)事件
        this.mouseMoveState = true;
        this.beginClientX = e.clientX;
      }
    },
    //驗(yàn)證成功函數(shù)
    successFunction() {
      this.confirmSuccess = true;
      this.confirmWords = "驗(yàn)證通過(guò)";
      if (window.addEventListener) {
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mousemove", this.mouseMoveFn);
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mouseup", this.moseUpFn);
      } else {
        document
          .getElementsByTagName("html")[0]
          .removeEventListener("mouseup", () => {});
      }
      document.getElementsByClassName("drag_text")[0].style.color = "#fff";
      document.getElementsByClassName("handler")[0].style.left =
        this.maxWidth + "px";
      document.getElementsByClassName("drag_bg")[0].style.width =
        this.maxWidth + "px";
    },
    //mousemove事件
    mouseMoveFn(e) {
      if (this.mouseMoveState) {
        let width = e.clientX - this.beginClientX;
        if (width > 0 && width <= this.maxWidth) {
          document.getElementsByClassName("handler")[0].style.left =
            width + "px";
          document.getElementsByClassName("drag_bg")[0].style.width =
            width + "px";
        } else if (width > this.maxWidth) {
          this.successFunction();
        }
      }
    },
    //mouseup事件
    moseUpFn(e) {
        console.log('moseUpFn' + e.clientX)
      this.mouseMoveState = false;
      var width = e.clientX - this.beginClientX;
      if (width < this.maxWidth) {
        document.getElementsByClassName("handler")[0].style.left = 0 + "px";
        document.getElementsByClassName("drag_bg")[0].style.width = 0 + "px";
      }
    },
  },
  mounted() {
    this.maxWidth =
      this.$refs.dragDiv.clientWidth - this.$refs.moveDiv.clientWidth;
    document
      .getElementsByTagName("html")[0]
      .addEventListener("mousemove", this.mouseMoveFn);
    document
      .getElementsByTagName("html")[0]
      .addEventListener("mouseup", this.moseUpFn);
  },
};
</script>

6 源碼下載

https://dxz.jb51.net/202306/yuanma/login-demo_jb51.rar

7 問(wèn)題解決

①項(xiàng)目一直報(bào)錯(cuò)

解決:由于安裝 vue-router 時(shí),直接運(yùn)行了 npm install vue-router 命令,造成直接下載最新版 vue-router 4.x,而 4 以后的版本適用于 vue3.0 版本,用在 vue2.0+ 會(huì)報(bào)錯(cuò),故換版本

② 背景圖存在白邊

可以看見(jiàn),左右都有白邊,采用了最粗暴的方法,給body的樣式margin:0px可以解決,上面也寫(xiě)到了

到此這篇關(guān)于vue2和elementUI 實(shí)現(xiàn)落日余暉登錄頁(yè)和滑塊校驗(yàn)功能的文章就介紹到這了,更多相關(guān)vue2和elementUI 登錄頁(yè)和滑塊校驗(yàn)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

荥经县| 罗江县| 昂仁县| 桃源县| 和田县| 阳城县| 阜平县| 康定县| 城步| 柘城县| 武汉市| 湖北省| 淳安县| 缙云县| 福清市| 温州市| 沙田区| 安西县| 沾化县| 左权县| 南丹县| 建始县| 三门县| 亚东县| 江川县| 台州市| 永胜县| 调兵山市| 吉木萨尔县| 聂荣县| 聊城市| 财经| 六枝特区| 宁陵县| 鄯善县| 南安市| 筠连县| 奉贤区| 隆昌县| 北京市| 卫辉市|