学习【全栈之巅】Node.js + Vue.js 全栈开发王者荣耀手机端官网和管理后台学习笔记(2.15-2.16)

学习【全栈之巅】Node.js + Vue.js 全栈开发王者荣耀手机端官网和管理后台学习笔记(2.15-2.16)

本项目是 学习Bilibili 全栈之巅 视频教程相关源码和体会
https://gitee.com/blaunicorn/node-vue-wangzherongyao
持续更新中…

2.15 广告位轮播图

// admin\src\views\Main.vue
          <el-menu-item-group>
            <template slot="title">广告位</template>
            <el-menu-item index="/ad/create">新建广告位</el-menu-item>
            <el-menu-item index="/ad/list">广告位列表</el-menu-item>
          </el-menu-item-group>
// admin\src\router\index.js
            {
                path: '/ad/create',
                name: 'AdCreate',
                component: () => import('../views/AdEdit.vue')
            },
            {
                path: '/ad/edit/:id',
                name: 'AdEdit',
                component: () => import('../views/AdEdit.vue'),
                props: true // 允许参数注入
            },
            {
                path: '/ad/list',
                name: 'AdList',
                component: () => import('../views/AdList.vue')
            }

admin端src/views新建 AdEdit.vue AdList.vue

server端model下新建Ad.js

const mongoose = require('mongoose')

// 定义模型字段 一个广告位内要有多个广告
const schema = new mongoose.Schema({
    name: { type: String },
    items: [{
        image: { type: String },
        url: { type: String },
        title: { type: String },

    }],
})

// 导出Item模型,哪里需要用,哪里引入,引入到 routes/admin/index.js
module.exports = mongoose.model('Ad', schema)

2.16 管理员账号设置

// 服务端设置模型  server/models/AdminUser.js
const mongoose = require('mongoose')

const schema = new mongoose.Schema({
    username: { type: String },
    password: { type: String }
})

module.exports = mongoose.model('AdminUser', schema)

管理端main.vue页面设置联接
router/index.js设置路由
服务端安装插件,并建立模型,密码加盐

// npm i bcrypt  // 因gyp错误未安装成功,改成
npm install bcryptjs
// server\models\AdminUser.js
// let bcrypt= require('bcryptjs')  可以定义变量引用,也可以直接引用
const mongoose = require('mongoose')

const schema = new mongoose.Schema({
    username: { type: String },
    password: {
        type: String,
        required: true,
        select: false,//防止查询出密码,此时前端查询返回的密码值为空
        set(val) {
            // 散列同步方法,第二个参数为加密指数
            return require('bcryptjs').hashSync(val, 12)
        }
    }
})

module.exports = mongoose.model('AdminUser', schema)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值