首页 > 其他分享 >vue2 项目25

vue2 项目25

时间:2023-01-02 10:44:36浏览次数:45  
标签:25 vue name 项目 router vue2 import home id

app.js:

<template>
  <div id="app">
    <router-view></router-view>
  </div>
</template>

<style lang="less">
body,
html {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}

[v-cloak]{
    display: none;
}

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  height: 100%;
  width: 100%;
}

nav {
  padding: 30px;

  a {
    font-weight: bold;
    color: #2c3e50;

    &.router-link-exact-active {
      color: #42b983;
    }
  }
}
</style>

  mylogin:

<template>
  <div id="login">
    <div class="middle">
      <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="50px" class="demo-ruleForm">
        <el-form-item prop="email" label="邮箱" :rules="[
          { required: true, message: '请输入邮箱地址', trigger: 'blur' },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ]">
          <el-input v-model.trim="ruleForm.email"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
          <el-input type="password" v-model.trim="ruleForm.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')">登录</el-button>
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    return {
      ruleForm: {
        pass: '',
        email: ''
      },
      rules: {
        pass: [
          { validator: validatePass, trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      console.log(formName);
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(valid);
          if (this.ruleForm.email === '[email protected]' && this.ruleForm.pass === '123') {
             // 登录成功
            // 1. 存储 token
            localStorage.setItem('token', 'Bearer xxxx')
            // 2. 跳转到后台主页
            this.$router.push('/home')
          } else {
            alert('error submit!!');
            localStorage.removeItem('token')
          }
        } else {
          alert('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>

<style lang="less" scoped>
#login {
  width: 100%;
  height: 100%;
  background-image: linear-gradient(to right, #fbc2eb, #a6c1ee);
  position: absolute;
  top: 50%;
  left: 48.9%;
  -webkit-transform: translate(-50%,-50%);
  transform: translate(-50%,-50%);
  padding: 0 20px;
  max-width: 100%;
}
.middle{
  width: 40%;
  margin: auto;
  .demo-ruleForm{
    margin: 25%;
    margin-top: 50%;
  }
}
</style>

  HomeView:

<template>
  <div class="home">
    <Header></Header>
    <div class="Side">
      <Side></Side>
      <div class="side-router">
        <router-view></router-view>
      </div>
    </div>

  </div>
</template>

<script>
import Header from '../components/Header.vue'
import Side from '../components/Side.vue'
export default {
  components: {
    Header, Side
  }
}
</script>
<style lang="less" scoped>
.home{
  height: 100%;
  display: flex;
  flex-direction: column;
}
.Side{
  height: 100%;
  display: flex;
  .side-router{
    padding: 15px;
    flex: 1;
  }
}
</style>

  路由--index:

import Vue from 'vue'
import VueRouter from 'vue-router'
import myLogin from '../views/myLogin.vue'
import pathArr from '@/router/pathArr.js'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/login' },
    // 登录的路由规则
    { path: '/login', component: myLogin },
    {
      path: '/home',
      name: 'home',
      component: () => import('../views/HomeView.vue'),
      redirect: '/home/users',
      children: [
        { path: 'users', name: 'users', component: () => import('../components/side/MyUsers.vue') },
        { path: 'rights', component: () => import('../components/side/MyRights.vue') },
        { path: 'goods', component: () => import('../components/side/MyGoods.vue') },
        { path: 'orders', component: () => import('../components/side/MyOrders.vue') },
        { path: 'settings', component: () => import('../components/side/MySettings.vue') },
        // 用户详情页
        { path: 'userinfo/:id', component: () => import('../components/side/user/info.vue'), props: true }
      ]
    }

  ]
})

// 全局前置守卫
router.beforeEach(function (to, from, next) {
  if (pathArr.indexOf(to.path) !== -1) {
    const token = localStorage.getItem('token')
    if (token) {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
})

export default router

  patharr.js:

export default ['/home', '/home/users', '/home/rights', '/home/goods', '/home/settings', '/home/orders']

  组件页面:

  MyUsers:

<template>
  <div>
    <template>
      <el-table :data="tableData" height="100%" border style="width: 100%">
        <el-table-column prop="date" label="日期" width="180">
        </el-table-column>
        <el-table-column prop="name" label="姓名" width="180">
        </el-table-column>
        <el-table-column prop="address" label="地址">
        </el-table-column>
        <el-table-column label="操作" prop="id">
          <!-- 获取id prop="id"-->
          <template slot-scope="scope">
            <!-- 传递id scope.row.id-->
            <div @click.prevent="operation(scope.row.id)">
              详情
            </div>
          </template>
        </el-table-column>
      </el-table>
    </template>
  </div>
</template>

<script>
export default {
  name: 'MyUser',
  data() {
    return {
      tableData: [{
        id: 1,
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        id: 2,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        id: 3,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        id: 4,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        id: 5,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        id: 6,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        id: 7,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }]
    }
  },
  methods: {
    gotoDetail(id) {
      //   /home/userinfo/1
      //   /home/userinfo/2
      //   /home/userinfo/3
      this.$router.push('/home/userinfo/' + id)
    },
    operation(id) {
      // console.log('ok');
      this.$router.push('/home/userinfo/' + id)
    }
  }
}
</script>

<style lang="less" scoped>

</style>

  MySettings:

<template>
  <h4 class="text-center">系统设置</h4>
</template>

<script>
export default {
  name: 'MySettings'
}
</script>

<style lang="less" scoped>
</style>

  MyRights:

<template>
  <h4 class="text-center">权限管理</h4>
</template>

<script>
export default {
  name: 'MyRights'
}
</script>

<style lang="less" scoped>
</style>

  MyOrders:

<template>
  <h4 class="text-center">订单管理</h4>
</template>

<script>
export default {
  name: 'MyOrders'
}
</script>

<style lang="less" scoped>
</style>

  MyGoods:

<template>
  <h4 class="text-center">商品管理</h4>
</template>

<script>
export default {
  name: 'MyGoods'
}
</script>

<style lang="less" scoped>
</style>

  Header:

<template>
    <div class="header">
        <div class="header_com">
            <el-row>
                <el-col :span="12">
                    <div class="grid-content bg-purple">
                        <el-image style="width: 50px; height: 50px; display:flex;margin-top: 5px;" :src="url">
                        </el-image>
                        <p>后台管理系统</p>
                    </div>
                </el-col>
                <el-col :span="12">
                    <div class="grid-content bg-purple-light" @click="Logout">退出登录</div>
                </el-col>
            </el-row>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            url: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg'
        }
    },
    methods: {
        Logout() {
            localStorage.removeItem('token')
            this.$router.push('/login')
        }
    }
}
</script>

<style lang="less" scoped>
.header {
    width: 100%;
    height: 60px;
    line-height: 60px;
    background: #545c64;

    .header_com {
        width: 90%;
        margin: auto;
        line-height: 60px;

        .bg-purple {
            display: flex;

            p {
                padding-left: 20px;
                line-height: 30px;
                color: #fff;
            }
        }

        .bg-purple-light {
            display: flex;
            justify-content: flex-end;
            color: #fff;
        }
    }
}
</style>

  Side:

<template>
    <div class="side">
        <el-row class="tac">
            <el-col :span="12">
                <el-menu default-active="2" class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose"
                    background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
                    <router-link to="/home/users">
                        <el-submenu index="1">
                            <template slot="title">
                                <i class="el-icon-user-solid"></i>
                                用户管理
                            </template>
                            <el-menu-item-group>
                                <template slot="title">分组一</template>
                                <el-menu-item index="1-1">选项1</el-menu-item>
                                <el-menu-item index="1-2">选项2</el-menu-item>
                            </el-menu-item-group>
                            <el-menu-item-group title="分组2">
                                <el-menu-item index="1-3">选项3</el-menu-item>
                            </el-menu-item-group>
                            <el-submenu index="1-4">
                                <template slot="title">选项4</template>
                                <el-menu-item index="1-4-1">选项1</el-menu-item>
                            </el-submenu>
                        </el-submenu>
                    </router-link>
                    <router-link to="/home/rights">
                        <el-menu-item index="2">
                            <i class="el-icon-menu"></i>
                            权限管理
                        </el-menu-item>
                    </router-link>
                    <router-link to="/home/goods">
                        <el-menu-item index="3">
                            <i class="el-icon-document"></i>
                            商品管理
                        </el-menu-item>
                    </router-link>
                    <router-link to="/home/orders">
                        <el-menu-item index="4">
                            <i class="el-icon-edit-outline"></i>
                            订单管理
                        </el-menu-item>
                    </router-link>
                    <router-link to="/home/settings">
                        <el-menu-item index="5">
                            <i class="el-icon-setting"></i>
                            系统设置
                        </el-menu-item>
                    </router-link>
                </el-menu>
            </el-col>
        </el-row>
    </div>
</template>

<script>
export default {
    methods: {
        handleOpen(key, keyPath) {
            console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
            console.log(key, keyPath);
        }
    }
}

</script>

<style lang="less" scoped>
a {
    text-decoration: none;
}

.side {
    width: 220px;
    height: 100%;
    background: #545c64;

    .el-menu {
        border-right: none
    }
}

.el-menu-vertical-demo {
    width: 218px;
}
</style>

  info:

<template>
  <div>
    <h4 class="text-center">用户详情页 ———————— {{ id }}</h4>
    <button @click="$router.back()">后退</button>
  </div>
</template>

<script>
export default {
  name: 'Myinfo',
  props: ['id']
}
</script>

<style lang="less" scoped>

</style>

  main:

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

Vue.use(ElementUI)

Vue.config.productionTip = false

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

  .eslintrc.js:

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  parserOptions: {
    parser: '@babel/eslint-parser'
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    // 在方法的形参()之前,是否加上空格
    "space-before-function-paren": ["warn", "never"],
    // 组件名字检测
    "vue/multi-word-component-names": "off",
    // 关闭空格检测
    "indent": 0,
    'semi':0
  }
}

  

标签:25,vue,name,项目,router,vue2,import,home,id
From: https://www.cnblogs.com/wencaiguagua/p/17019510.html

相关文章

  • 为 ASPNETCORE 7 项目添加 Serilog
    本文将介绍如何为ASP.NETCore项目添加Serilog。添加Serilog首先,我们需要在项目中添加Serilog的NuGet包。dotnetaddpackageSerilog.AspNetCore修改Progra......
  • 史上最全的 pom.xml 文件详解(扩展:Maven的三种项目打包方式——pom,jar,war的区别)
    史上最全的pom.xml文件详解https://blog.csdn.net/jk418756/article/details/87917776?spm=1001.2101.3001.6650.12&utm_medium=distribute.pc_relevant.none-task-blog......
  • 在线视频项目学习笔记(三)—前台登录相关
    一、短信验证码接口分析1.首先第一点需要注意的就是短信验证码接口和登录接口不是一个接口,短信验证码接口是前端界面一点击发送验证码调用的,登录接口是前端在填上验证码以......
  • 图谱项目启动
    VUE(kgsecond)启动项目管理器:H:vueui选择kgsecode先build->server(保险起见)项目创建:选择npminit.project选择配置项,去掉mapper,加上router选择......
  • 好题分享、心路历程(力扣1225)
    【题目介绍】该题为力扣1225,名为报告系统状态的连续日期。【题型分类】属于连续专题。官网标为困难题。【思路分享】这里的连续属于时间连续,采用row_number()、subd......
  • 通过Xcode将项目同步到GitHub上
    主要参考这篇文章:​​http://www.mindthe.net/devices/2011/04/28/12-steps-to-using-github-with-xcode-4/​​1.在Xcode上​​新建一个Repository​​:2.获取新建仓库的S......
  • 解读Datasheet系列:W25Q80DV(华邦 SPI Flash)
    本文只对W25Q80DV数据手册的一部分进行解读,其涵盖的内容基本足够开发标准SPI接口的Linux驱动和裸板驱动。完整的Datasheet下载:##一般描述W25Q80DV(8M-bit)是一个串行......
  • web项目开发---第三天
    ssm核心业务crm项目的简介:CustomerrelationshipManagement客户关系管理系统销售或者贸易型公司使用。企业级应用,内部员工使用。java开发的传统软件。CRM项目的宗旨......
  • SpringBoot 项目实战 | 瑞吉外卖
    一、软件开发整体介绍1、软件开发流程2、角色分工项目经理:对整个项目负责,任务分配、把控进度产品经理:进行需求调研,输出需求调研文档、产品原型等UI设计师:根据产品原......
  • .Net 7 团队把国内的龙芯确实当做一等公民和弃用的项目
    楔子:国内龙芯据说是用的自己的指令集,在研究ILC的时候,发现了龙芯在微软那边确实是一等公民的存在。龙芯官网龙芯平台.NET,是龙芯公司基于开源社区.NET独立研发适配的龙......