vue3.0 登录页demo

1、login.vue

<template>
  <!-- 登录页头部 start -->
  <div class="login-top">
    <img src="./icon-header.svg" class="icon-head" alt="" />
    <div class="login-top-centent">欢迎登录</div>
    <div class="title-name">hello word 系统</div>
  </div>
  <!-- 登录页头部 end -->
  <!-- 登录页面主体 start -->
  <div class="login-body">
    <!-- 用户名 -->
    <div class="field">
      <svg-icon icon-name="wo" class-name="icon"/>
      <input type="text" placeholder="请输入用户名" v-model="username" />
    </div>
    <!-- 密码 -->
    <div class="field">
      <svg-icon  icon-name="mima" class-name="icon"/>
      <input type="password" placeholder="请输入密码" v-model="password" />
    </div>
    <!-- 记住密码 -->
    <div class="field-check">
      <input
        type="checkbox"
        class="checkbox"
        id="remberpwd"
        value="记住密码"
        v-model="remberpwd"
      />
      <label class="checkbox-lable" for="remberpwd">记住密码</label>
    </div>
    <!-- 登录按钮 -->
    <button class="login" @click="login">登录</button>
  </div>
  <!-- 登录页面主体 end -->
</template>

<script>
import { onMounted, reactive, toRefs, watch } from 'vue'
//引入路由
import { useRouter } from 'vue-router'
export default {
  name: 'app',
  setup() {
    const state = reactive({
      username: null, //用户名
      password: null, //密码
      remberpwd: false, //记住密码
    })
    const router = useRouter()
    // 页面初始化时,赋值用户名密码
    onMounted(() => {
      console.log(localStorage)
      if (localStorage.getItem('username')) {
        state.username = localStorage.getItem('username')
        state.password = localStorage.getItem('password')
        state.remberpwd = true
      }
    })
    // 记住密码
    watch(
      () => state.remberpwd,
      val => {
        remberPassword(val)
      }
    )
    //记住密码
    const remberPassword = val => {
      if (val === true) {
        localStorage.setItem('username', state.username)
        localStorage.setItem('password', state.password)
      } else {
        localStorage.removeItem('username')
        localStorage.removeItem('password')
      }
    }
    // 验证用户名密码
    const login = () => {
      // //记住密码
      // remberPassword(state.username)
      if (state.username === 'admin' && state.password === '123456') {
        //跳转首页
        router.push('/home')
      } else {
        alert('用户名或者密码错误')
      }
    }

    return {
      ...toRefs(state),
      login,
    }
  },
}
</script>

<style scoped>
/**头部内容 */
.login-top {
  height: 200px;
  background: linear-gradient(
    to right,
    rgba(0, 0, 240, 0.5),
    rgba(94, 94, 233, 0.5)
      /* rgba(254, 172, 94, 0.5),
    rgba(199, 121, 208, 0.5) */
  );
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border-radius: 50% / 0 0 20% 20%;
}

/**文本头部内容 */
.icon-head {
  width: 40px;
  float: clear;
}
.login-top-centent {
  padding-top: 10px;
  text-align: center;
  color: #ffffff;
  font-size: 20px;
}
.title-name {
  text-align: center;
  color: #ffffff;
  font-size: 18px;
}
/**主体内容 */
.login-body {
  margin: 0 auto;
  margin-top: -20px;
  width: 85%;
  background: #ffffff;
  box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.1);
  opacity: 1;
  border-radius: 10px;
  padding: 60px 0;
  height: calc(100% - 200px);
}
.field {
  width: 70%;
  margin: 0 auto;
  margin-top: 30px;
  border-bottom: 1px solid rgb(204, 203, 203);
  /* 图标输入框对齐 */
  display: flex;
  align-items: center;
  padding: 5px 0;
}
.icon {
  font-size: 22px;
  color: rgba(0, 0, 240, 0.5);
}
input {
  border: 0;
  font-size: 13px;
}
input::-webkit-input-placeholder {
  color: rgba(0, 0, 240, 0.5);
  font-size: 13px;
}
input:focus {
  /* 边框不用border,用outline */
  outline: 0px;
}
/* 多选框 */
.field-check {
  margin: 0 auto;
  margin-top: 10px;
  width: 70%;
  text-align: right;
}
.checkbox-lable {
  padding-left: 5px;
  cursor: pointer;
  margin: 0;
  vertical-align: middle;
  font-size: 13px;
}
.checkbox {
  display: inline-block;
  vertical-align: middle;
  margin-bottom: 2px;
}
/* css 复选框 */
input[type='checkbox'] {
  cursor: pointer;
  position: relative;
}

input[type='checkbox']::after {
  position: absolute;
  top: 0;
  background-color: #fff;
  color: #fff;
  width: 14px;
  height: 14px;
  display: inline-block;
  visibility: visible;
  padding-left: 0px;
  text-align: center;
  content: ' ';
  border-radius: 2px;
  box-sizing: border-box;
  border: 1px solid #ddd;
}

input[type='checkbox']:checked::after {
  content: '';
  background-color: rgba(94, 94, 233, 0.5);
  /* border-color: rgba(94, 94, 233, 0.5); */
}

input[type='checkbox']:checked::before {
  content: '';
  position: absolute;
  top: 1px;
  left: 5px;
  width: 3px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
  z-index: 1;
}

/* 登录按钮 */
.login {
  width: 70%;
  margin-top: 30px;
  border: 0px;
  height: 40px;
  border-radius: 10px;
  background: rgba(0, 0, 240, 0.5);
  color: #ffffff;
}
button:focus {
  /* 边框不用border,用outline */
  outline: 0px;
}
</style>

2.SvgIcon.vue


<template>
  <svg :class="svgClass" aria-hidden="true">
    <use :xlink:href="iconName" />
  </svg>
</template>

<script>
export default {
    name: 'svg-icon',
    props: {
        iconName: {
            type: String,
            required: true,
        },
        className: {
            type: String,
        },
    },
    computed: {
        iconName() {
            return `#icon-${this.iconName}`;
        },
        svgClass() {
            if (this.className) {
                return 'svg-icon ' + this.className;
            } else {
                return 'svg-icon';
            }
        },
    },
};
</script>

<style scoped>
.svg-icon {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    fill: currentColor;
    overflow: hidden;
}
</style>

3.mian.js里面svgicon组件的全局注册

import { createApp } from 'vue';
import App from './App.vue';
// 路由
import router from './router';
// 全局引入vant样式
import 'vant/lib/index.css';
//rem 基准
import 'utils/rem';
const app = createApp(App);
app.use(router).mount('#app');


// 全局注册icon组件
import 'assets/iconfont/iconfont.js';
import SvgIcon from 'components/SvgIcon';
app.component('svg-icon', SvgIcon);

npm install svg-sprite-loader  -save-dev

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很高兴为您介绍一个基于Vue 3和Three.js的项目实例。 这个项目是一个可视化的3D项目,使用了Vue 3和Three.js来实现。它包含了一些常用的功能,如场景、灯光、摄像机初始化,模型和天空盒的加载,以及鼠标点击和悬浮的事件交互。 您可以在以下链接中预览这个项目:[项目预览地址](https://stevenfeng.cn/threejs-demo/) 在这个项目中,主要使用了Vue 3的组件化开发方式来封装Three.js的API。其中,场景的初始化和渲染使用了一个名为`Viewer`的组件。这个组件包含了一些基础功能,如场景的创建、灯光的添加、摄像机的初始化等。 以下是一个简单的示例代码,展示了如何在Vue 3中使用Three.js来创建一个场景: ```vue <template> <div ref="container"></div> </template> <script> import { ref, onMounted } from 'vue'; import * as THREE from 'three'; export default { name: 'Viewer', setup() { const container = ref(null); let scene, camera, renderer; onMounted(() => { // 创建场景 scene = new THREE.Scene(); // 创建相机 camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); camera.position.z = 5; // 创建渲染器 renderer = new THREE.WebGLRenderer({ antialias: true }); renderer.setSize(window.innerWidth, window.innerHeight); container.value.appendChild(renderer.domElement); // 添加一个立方体到场景中 const geometry = new THREE.BoxGeometry(); const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 }); const cube = new THREE.Mesh(geometry, material); scene.add(cube); // 渲染场景 function animate() { requestAnimationFrame(animate); cube.rotation.x += 0.01; cube.rotation.y += 0.01; renderer.render(scene, camera); } animate(); }); return { container, }; }, }; </script> <style> #container { width: 100%; height: 100%; } </style> ``` 这个示例代码创建了一个名为`Viewer`的Vue组件,它在面上渲染一个包含一个立方体的Three.js场景。在`setup`函数中,我们使用了Vue 3的`ref`和`onMounted`来获取DOM元素的引用和在组件挂载后执行的回调函数。 在回调函数中,我们创建了一个Three.js的场景、相机和渲染器,并将渲染器的输出添加到组件的DOM元素中。然后,我们创建了一个立方体,并将其添加到场景中。最后,我们使用`requestAnimationFrame`来实现动画效果,不断更新立方体的旋转角度并渲染场景。 这只是一个简单的示例,实际的项目中可能会涉及更多的功能和复杂的场景。您可以根据自己的需求来扩展和修改这个示例。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值