一泡态、頁(yè)面編寫(xiě)
- 編寫(xiě)登錄頁(yè)面
src 目錄下新建目錄 views
編寫(xiě) views/admin/Login.vue
<template>
<div class="container">
<el-form ref="form" :model="form" label-width="80px" class="login-page" >
<h2>Boot電商后臺(tái)登錄</h2>
<el-form-item label="用 戶(hù):" prop="username">
<el-input v-model="form.username" placeholder="請(qǐng)輸入用戶(hù)名">
<el-button slot="prepend" icon="el-icon-user"></el-button>
</el-input>
</el-form-item>
<el-form-item label="密 碼:">
<el-input v-model="form.password" type="password" placeholder="請(qǐng)輸入密碼">
<el-button slot="prepend" icon="el-icon-key"></el-button>
</el-input>
</el-form-item>
<el-button type="primary" icon="el-icon-user-solid" @click="login">登 錄</el-button>
</el-form>
</div>
</template>
<script>
export default {
data() {
return {
form: {
username: "",
password: ""
}
};
},
methods: {
}
}
};
</script>
<style scoped>
.container {
margin-top: 200px;
width: 100%;
height: 100%;
}
.login-page {
border-radius: 5px;
margin: auto;
width: 350px;
padding: 35px 55px 15px;
background: #fff;
border: 1px solid #eaeaea;
box-shadow: 0 0 25px #cac6c6;
}
</style>
- 添加路由
訪問(wèn) login 要跳轉(zhuǎn)到登錄頁(yè)面
修改 router/index.js 為
import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'login',
component: () => import('./views/Login.vue')
}
]
})
- 數(shù)據(jù)校驗(yàn)
from元素添加校驗(yàn)屬性::rules="rules"
<el-form ref="form" :model="form" label-width="80px" class="login-page" :rules="rules">
元素添加:prop="username"
<el-form-item label="用 戶(hù):" prop="username">
data添加屬性:
data() {
return {
form: {
username: "",
password: ""
},
rules: {
username: [{ required: true, message: "請(qǐng)輸入用戶(hù)名", trigger: "blur" }]
}
};
},
methods添加校驗(yàn)方法:
methods: {
login() {
// 數(shù)據(jù)校驗(yàn)
this.$refs.form.validate(valid => {
if (valid) {
console.log('驗(yàn)證成功')
}
});
}
}