CSS基础

1.css书写

text-align        文本格式(居中、靠最右)

border: 1px slategray solid;        边框线设置

border-collapse:collapse;        边框单实线

:first-child        选择同类型标签的第1个标签

:last-child        选择同类型标签的最后1个标签

:nth-child(x)        选择同类型标签的第x个标签

th        表格头

td        表格行的单个单元格

2.axios使用

npm install axios   下载

import axios from 'axios';       引用

        get请求:

axios({
            method:'get',
            url:'http://114.67.241.121:8080/product/list'
        }).then(res => {
            console.log(res);
            this.products = res.data.data
            console.log(this.products);
        })

        post请求:

        (1)登录注册

handleSubmit() {

        axios.post('http://114.67.241.121:8088/user/login' , null , {
          params:{
            username : this.username,
            password : this.password
          }
        }).then(res=>{
              
              console.log(res)
              if(res.data.code==200){
                this.session = res.data.data.token

                //传session
                sessionStorage.setItem('token',this.session)

                //清除token缓存
                // sessionStorage.removeItem('token',this.session)
                this.$router.push({path:'/index'})
              }
              else {
                this.msg='用户名或密码错误'
                // alert('用户名或密码错误')
              }
              
        })
  
      },

         (2)get方法获取学生信息

//在created当中调用方法
created(){
        this.getStud()
      },


// 调用的方法
 //获取stu_list
        getStud(){
            axios.get('http://114.67.241.121:8088/stu/list',{
                headers:{
                    Authorization:this.token
                }
            }).then(res=>{
              
              console.log(res)
              this.lists = res.data.data 
        })
        },

        (3)新增学生

//data当中定义form表单
form:{
            stuid:'',
            stuno:'',
            stuname:'',
            stumajor:'',
            stugrade:'',
            stuaddess:'',
            stunative:''
          }

//新增stu
        AddStu(){
            const data = {
                
                    stuid:this.form.stuid,
                    stuno:this.form.stuno,
                    stuname:this.form.stuname,
                    stumajor:this.form.stumajor,
                    stugrade:this.form.stugrade,
                    stuphone:this.form.stuphone,
                    stuaddess:this.form.stuaddess,
                    stunative:this.form.stunative,
                
            }
            axios.post('http://114.67.241.121:8088/stu/add',data,
            {
                headers:{
                    Authorization:this.token
                }
            }
            ).then(res=>{
              if(res.data.code == 200){
                alert('添加成功')
                //关闭弹窗
                this.dialogFormVisible = false;
                this.$router.go(0);
              }
              
              
        })
        },

        (4)修改

//更新数据
        Update() {
            // console.log(row);
            const data = {
                
                stuid:this.form.stuid,
                stuno:this.form.stuno,
                stuname:this.form.stuname,
                stumajor:this.form.stumajor,
                stugrade:this.form.stugrade,
                stuphone:this.form.stuphone,
                stuaddess:this.form.stuaddess,
                stunative:this.form.stunative,
            
        }
        axios.post('http://114.67.241.121:8088/stu/edit',data,
        {
            headers:{
                Authorization:this.token
            }
        }
        ).then(res=>{
          if(res.data.code == 200){
            alert('修改成功')
            //关闭弹窗
            this.dialogFormVisible = false;
            this.$router.go(0);
          }
          
          
    })
        },

        (5)删除

//删除
           Delete(s){
            this.stuid = s.stuid
            axios.post('http://114.67.241.121:8088/stu/del',null,{
                headers:{
                    Authorization:this.token
                },
                params:{
                    stuid:this.stuid
                }
            },
            ).then(res=>{
              console.log(this.form.stuid);
              alert('删除成功');
              this.lists = res.data.data;
              this.$router.go(0);
        })
           },

实验代码心得

Login

<template>
    <div class="login">
      <h1>登录</h1>
        <div class="form-group">
            <span  class="msg">{{msg}}</span><br>
          <label for="username">用户名</label>
          <input name= 'username' type="username" id="username" v-model="username" required />
        </div>
        <div class="form-group">
          <label for="password">密码</label>
          <input name="password" type="password" id="password" v-model="password" required />
        </div>
        <button  v-on:click="handleSubmit()" type="submit">登录</button>
    </div>
  </template>
  
  <script>
  import axios from 'axios';
// import router from '@/router';
  export default {
    data() {
      return {
        username: '',
        password: '',
        session:'',
        msg:''
      };
    },
    methods: {
      handleSubmit() {

        axios.post('http://114.67.241.121:8088/user/login' , null , {
          params:{
            username : this.username,
            password : this.password
          }
        }).then(res=>{
              
              console.log(res)
              if(res.data.code==200){
                this.session = res.data.data.token
                //传session
                sessionStorage.setItem('token',this.session)
                //清除token缓存
                // sessionStorage.removeItem('token',this.session)
                this.$router.push({path:'/index'})
              }
              else {
                this.msg='用户名或密码错误'
                // alert('用户名或密码错误')
              }
              
        })
  
      },
    },
  };
  </script>
  
  <style scoped>


  .login {
    width: 300px;
    margin: 0 auto;
    text-align: center;
    background-color: #e2f3f9;
    padding: 100px;
    margin: 150px auto;
    border-radius: 10px;
    
  }
  
  .form-group {
    margin-bottom: 10px;
  }
  
  label {
    display: inline-block;
    width: 80px;
  }
  
  input {
    width: 200px;
  }
  
  button {
    width: 100px;
  }

  .msg {
    color: red;
  }
  </style>
  

Index

<template>
    <div>
        <!-- 弹窗 -->
        <el-button type="text" @click="Show1">新增学生</el-button>

        <el-dialog :title="isEdit?'新增':'修改'" :visible.sync="dialogFormVisible"
        @close="HandClose">
            <el-form :model="{form}">
            <!-- <el-form-item label="id" :label-width="formLabelWidth">
                <el-input v-model="form.stuid" autocomplete="off"></el-input>
            </el-form-item> -->
            <el-form-item label="学号" :label-width="formLabelWidth">
                <el-input v-model="form.stuno" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="姓名" :label-width="formLabelWidth">
                <el-input v-model="form.stuname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="职位" :label-width="formLabelWidth">
                <el-input v-model="form.stumajor" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="年级" :label-width="formLabelWidth">
                <el-input v-model="form.stugrade" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="电话" :label-width="formLabelWidth">
                <el-input v-model="form.stuphone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="地址" :label-width="formLabelWidth">
                <el-input v-model="form.stuaddess" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="国际" :label-width="formLabelWidth">
                <el-input v-model="form.stunative" autocomplete="off"></el-input>
            </el-form-item>
            </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="handleSubmmit">确 定</el-button>
        </div>
        </el-dialog>


    
    <el-table
      :data="lists"
      stripe
      style="width: 100%">
      <el-table-column
        prop="stuid"
        label="id">
      </el-table-column>
      <el-table-column
        prop="stuno"
        label="学号">
      </el-table-column>
      <el-table-column
        prop="stuname"
        label="姓名">
      </el-table-column>
      <el-table-column
        prop="stumajor"
        label="职位">
      </el-table-column>
      <el-table-column
        prop="stugrade"
        label="年级">
      </el-table-column>
      <el-table-column
        prop="stuphone"
        label="电话">
      </el-table-column>
      <el-table-column
        prop="stuaddess"
        label="地址">
      </el-table-column>
      <el-table-column
        prop="stunative"
        label="国籍">
      </el-table-column>
      <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="row">
        <el-button @click="Show2(row.row)" type="text" size="small">修改</el-button>
        <el-button @click="Delete(row.row)" type="text" size="small">删除</el-button>
      </template>
    </el-table-column>
    </el-table>

    
    
</div>
  </template>
  
  <script>
import axios from 'axios';
    export default {
      data() {
        return {

          lists:[],
          //接收session
          token:sessionStorage.getItem('token'),
          dialogTableVisible: false,
          dialogFormVisible: false,
          formLabelWidth: '120px',
          isEdit:true,
          
          form:{
            stuid:'',
            stuno:'',
            stuname:'',
            stumajor:'',
            stugrade:'',
            stuaddess:'',
            stunative:''
          }
        }
      },
      created(){
        this.getStud()
      },
      methods: {
        //更新数据
        Update() {
            // console.log(row);
            const data = {
                
                stuid:this.form.stuid,
                stuno:this.form.stuno,
                stuname:this.form.stuname,
                stumajor:this.form.stumajor,
                stugrade:this.form.stugrade,
                stuphone:this.form.stuphone,
                stuaddess:this.form.stuaddess,
                stunative:this.form.stunative,
            
        }
        axios.post('http://114.67.241.121:8088/stu/edit',data,
        {
            headers:{
                Authorization:this.token
            }
        }
        ).then(res=>{
          if(res.data.code == 200){
            alert('修改成功')
            //关闭弹窗
            this.dialogFormVisible = false;
            this.$router.go(0);
          }
          
          
    })
        },
        //获取stu_list
        getStud(){
            axios.get('http://114.67.241.121:8088/stu/list',{
                headers:{
                    Authorization:this.token
                }
            }).then(res=>{
              
              console.log(res)
              this.lists = res.data.data 
        })
        },
        //逻辑判断
        Show1(){
            //打开弹窗
            this.dialogFormVisible = true;
        },
        Show2(s){
            //打开弹窗
            this.dialogFormVisible = true;
            //变成编辑
            this.isEdit = false;

            this.form.stuid = s.stuid

        },
        //新增stu
        AddStu(){
            const data = {
                
                    stuid:this.form.stuid,
                    stuno:this.form.stuno,
                    stuname:this.form.stuname,
                    stumajor:this.form.stumajor,
                    stugrade:this.form.stugrade,
                    stuphone:this.form.stuphone,
                    stuaddess:this.form.stuaddess,
                    stunative:this.form.stunative,
                
            }
            axios.post('http://114.67.241.121:8088/stu/add',data,
            {
                headers:{
                    Authorization:this.token
                }
            }
            ).then(res=>{
              if(res.data.code == 200){
                alert('添加成功')
                //关闭弹窗
                this.dialogFormVisible = false;
                this.$router.go(0);
              }
              
              
        })
        },
        //提交表单
        handleSubmmit(){
            if(this.isEdit == true){
                this.AddStu();
            }
            else{
                this.Update();
            }
              
           },
           //删除
           Delete(s){
            this.stuid = s.stuid
            axios.post('http://114.67.241.121:8088/stu/del',null,{
                headers:{
                    Authorization:this.token
                },
                params:{
                    stuid:this.stuid
                }
            },
            ).then(res=>{
              console.log(this.form.stuid);
              alert('删除成功');
              this.lists = res.data.data;
              this.$router.go(0);
        })
           },
           //清空表单
           HandClose(){
                //重置表单数据
                this.form = {
                    stuid:'',
                    stuno:'',
                    stuname:'',
                    stumajor:'',
                    stugrade:'',
                    stuphone:'',
                    stuaddess:'',
                    stunative:''
                    };
           }

    },

      
    }
  </script>

  <style>
.el-form-item{
    
    
}
.el-input {
    
    
}


</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值