首页 > 其他分享 >第五篇 - 搭建一个Vue项目

第五篇 - 搭建一个Vue项目

时间:2023-05-31 14:13:10浏览次数:43  
标签:Vue return 50% height 第五篇 import message 搭建

上一节创建了一个Spring Boot的后端登录功能,接下来创建一个Vue项目实现前端登录页面

一、创建一个Vue项目

将Vue项目创建到spring boot demo1项目中。打开idea的Terminal,运行【vue init webpack vuetest】,后面都按enter/Y/n等就行。稍等一会,vue项目就创建好了。

 二、运行Vue项目

进入vuetest目录,运行【npm run dev】,访问http://localhost:8080

 出现以下界面,说明项目创建成功。

 三、配置Vue项目

参考链接:https://blog.csdn.net/weixin_51759592/article/details/125736948

首先在packge.json文件中添加依赖,axios是为跨域做准备。

 然后修改main.js

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import './assets/css/global.css'

Vue.use(ElementUI)
Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

 

 

 

修改HelloWorld.vue

/* eslint-disable */
<template>
  <div class="login_container">
    <div class="login_box">
      <div class="wai">
        <!-- 头像区域 -->
        <div class="avatar_box">
          <img src="../assets/head.png" alt="" />
        </div>
        <!-- 登录表单区域 -->
        <el-form
          ref="loginFormRef"
          :model="loginForm"
          :rules="loginFormRules"
          label-width="0px"
          class="login_form"
        >
          <!--        用户名-->
          <el-form-item prop="username">
            <el-input
              v-model="loginForm.username"
              prefix-icon="el-icon-user"
            ></el-input>
          </el-form-item>
          <!--        密码-->
          <el-form-item prop="password">
            <el-input
              v-model="loginForm.password"
              prefix-icon="el-icon-key"
              type="password"
            ></el-input>
          </el-form-item>
          <!--        按钮区域-->
          <el-form-item class="btns">
            <el-button type="primary" @click="Login">登录</el-button>
            <el-button type="info" @click="resetLoginForm">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
  .login_container {
    background-color: darkcyan;
    height: 100%;
  }

  .login_box {
    width: 350px;
    height: 300px;
    background-color: white;
    border-radius: 15px;
    /*容器内居中*/
    position: absolute;
    left: 40%;
    top: 50%;
    transform: translate(-50%, -50%);

    .avatar_box {
      height: 130px;
      width: 130px;
      border: 1px solid #eee;
      border-radius: 50%;
      padding: 10px;
      /*边框阴影*/
      box-shadow: 0 0 10px #ddd;
      position: absolute;
      left: 50%;
      transform: translate(-50%, -50%);
      background-color: #fff;

      img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
        background-color: #993d3d;
      }
    }

    .login_form {
      position: absolute;
      bottom: 0;
      width: 100%;
      padding: 0 20px;
      box-sizing: border-box;
    }

    .btns {
      display: flex;
      justify-content: flex-end;
    }
    .wai {
      background-image: url("../assets/back.jpg");
      width: 577px;
      height: 300px;
      border-radius: 15px;
    }
  }
</style>

<script>
export default {
  data () {
    return {
      // 数据绑定对象
      loginForm: {
        username: 'llll',
        password: '123'
      },
      loginFormRules: {
        // 验证用户
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
          {
            min: 3,
            max: 10,
            message: '长度在3到10个字符',
            trigger: 'blur'
          }
        ],
        password: [
          {required: true, message: '请输入登录密码', trigger: 'blur'},
          {
            min: 3,
            max: 15,
            message: '长度在3到15个字符',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  methods: {
    Login () {
      // 预验证
      this.$refs.loginFormRef.validate(async (valid) => {
        // 未验证通过则直接return
        if (!valid) return
        // 不加await的话不会打印出数据,await只能用于async修饰的函数
        const response = await this.$http.post('pro/login', this.loginForm)
          .catch(() => this.$message.error('登录失败,请联系Tel'))
        // console.log(response.data)
        if (response.status !== 200) return
        if (response.data.token) return this.$message.success('登录成功')
        if (response.data().error) return this.$message.error(response.data().error)
      })
    },
    // 重置登录表单
    resetLoginForm () {
      this.$refs.loginFormRef.resetFields()
    }
  }
}
</script>

 

 

注意格式,eslint检查,用单引号,函数之间的空格,不要用分号等。

在assets下新建一个css文件夹,在此文件夹下新建一个global.css,从网上下载2个图片放到assets文件夹下,分别是back.jpg和head.jpg

html,
body,
#app{
  height: 100%;
  margin: 0;
  padding: 0;
}

 

运行vuetest,【npm run dev】

 不过此时点登录是没有效果出现的。

标签:Vue,return,50%,height,第五篇,import,message,搭建
From: https://www.cnblogs.com/smart-zihan/p/17445937.html

相关文章

  • Vue07-Axios
    Axiosaxios是一个网络请求相关的库。axios:ajaxi/osystem使用axios编写的网络请求代码,可以运行在浏览器端,也可以在Node环境中运行。01.支持的请求方式axios(config)axios.request(config)axios.get(url[,config])axios.delete(url[,config])axios.head......
  • Vue+.net core 7 api跨域
    nginx的不说,直接说在项目中配置的。重点:前端要配代理,后端要设置返回的头文件信息。双管齐下1、前端在项目中的vue.config.js配置中进行设置module.exports={publicPath:'/',outputDir:'dist',//发布输入文件assetsDir:'static',//需要/demo目录下放打包后......
  • Vue computed property values was assigned to but it has no setter
    vue文件中的核心代码写法<template><div><v-select:items="filters"label="查询条件"solodenseclass="select-size"v-model="filterKey"clearable></v-sele......
  • vue监听浏览器窗口大小变化,做对应的操作
    页面初始化mounted的时候,通过document.body.clientWidth和document.body.clientHeight获取到浏览器的宽和高,然后通过window.onresize来监听浏览器窗口的变化,在这里来改变我们的变量宽和高即可。(created()的时候不行,因为此时document还没有生成)<template><sectionclass="p-1......
  • Vue+element搭建后台管理系统-六、实现权限管理
    在一些后台管理系统中,每个身份登录的权限不一样,以至于配置的菜单不一样。就我做过的小区物业管理系统而言,举个例子:业主登录网站只能看到社区服务中的投诉、维修以及查看公告。而管理员可以看到一些对本小区的基本操作,例如查看楼栋,查看业主,账单催缴等等…而超级管理员,可以看到所有......
  • Pycharm中开发vue element项目时eslint的安装和使用
    在PyCharm中使用ESLint对ElementUI进行语法检查和代码风格检查的配置步骤如下:确保你的项目已经配置了ESLint并且可以正常运行。如果尚未安装ESLint,请先使用npm(或者你的包管理器)在项目中安装ESLint:npminstalleslint--save-dev在项目根目录下创建一个名为.eslintrc.......
  • vue-cli详细说明
    vue-cli单页面应用程序单页面应用程序(SinglePageApplication)一个web网站只有唯一一个HTMl页面,所有功能&交互都在唯一一个页面完成vue-clivue-cli是vue.js开发的标准工具,简化了基于webpack创建工程化的Vue项目的过程。创建项目基于vue-cli快速生成工程化的Vue项目:vuecrea......
  • CentOS使用系统镜像搭建局域网Yum源
     一、防火墙配置CentOS7.x8.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。1、关闭firewall:systemctlstopfirewalld.service#停止firewallsystemctldisablefirewalld.service#禁止firewall开机启动systemctlmaskfirewalldsystemctlstopfirew......
  • VUE2/3差异之模板写法
    OptionsAPI(选项API)传统的组件随着业务复杂度越来越高,代码量会不断的加大,整个代码逻辑都不易阅读和理解。虽然尽量一个文件不要写太多代码(1000行内),但总有一些大型组件要一个文件写很多代码优点:各选项编写写位置固定,结构清晰缺点:代码组织性差,相似的逻辑代码不便于复用逻......
  • vue中v-bind使用三目运算符绑定class
    <template><div><!--外边框的样式--><div:class="projectStatus===2?outlineDelay:outline"@click="clickProject(userProjectId)"><!--延期--><divv-if="projectStatus===2"......