vue-cli3和element做⼀个简单的登陆页⾯
1.先⽤vue-cli3创建⼀个项⽬
2.安装element模块
全局安装
npm i element-ui -S
3在main.js引⼊模块
import ElementUI from'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);
4.这⾥先扩展⼀个⼩知识点
在package.json⽂件中scripts下serve,在后⾯加上--open 可以实现运⾏项⽬后⾃动打开浏览器
5.然后我们在views⽂件夹下新建⼀个登陆页⾯login.vue
6.搭建login页⾯(这⾥我们简单的⽤element修饰⼀下)
<template>
<div class="firstdemo">
<el-form ref="form" :model="form" label-width="80px">
<el-row type="flex" justify="center">
<el-col :span="5">
<el-form-item label="⽤户名">
<el-input v-model="form.name"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row type="flex" justify="center">
<el-col :span="5">
<el-form-item label="密码">
<el-input v-model="form.password"></el-input>
</el-form-item>
</el-col>
</el-row>
<el-row type="flex" justify="center">
<el-col :span="5">
<el-form-item>
<el-button type="primary" @click="onSubmit">登陆</el-button>
<el-button>注册</el-button>
</el-form-item>
</el-col>
</el-row>
</el-form>
</div>
</template>
<script>
export default {
name: "fisrtdemo",
data() {
return {
form: {
name: "",
password: ""
}
};
},
methods: {
onSubmit() {
if (this.form.name == "admin" && this.form.password == "123456") {
this.$message({
message: '登陆成功',
type: 'success'
});
this.$router.push({ path: "/Home" });
}else{
this.$('登陆失败');
}
}
}
};
</script>
<style lang="stylus" scoped></style>
由于只是简单的展⽰以下这⾥我们⽤⼀个死数据
这⾥简单强调⼀下在逻辑层实现路由切换
<!-- router.push({path:'/foo'}) -->
     <!-- 声明式导航应⽤于视图层 -->
<router-link to='/foo'>to foo</router-link>
<router-view></router-view>
<!-- 编程式导航应⽤于逻辑层-->
<!-- router.push({path:'/foo'}) -->
到这⾥login页⾯基本搭建完成
7.在router下的index.js中引⼊我们刚刚创建的login.vue
并对路径作相应改动
index.js
import Vue from"vue";
import VueRouter from"vue-router";
import Home from"../views/Home.vue";
import login from"../views/login.vue";
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "login",
component: login
},
{
path: "/Home",
name: "home",
component: Home
},
{
path: "/about",
name: "about",
/
vue element admin/ route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () =>
import(/* webpackChunkName: "about" */"../views/About.vue")
}
];
const router = new VueRouter({
mode: "history",
base: v.BASE_URL,
routes
});
export default router;
8.最后我们对home作⼀下简单修饰。
博主这⾥在components中新建了⼀个组件helloworld并引⼊了element中的⼀个简单的布局容器。
然后在home页⾯引⼊helloworld对页⾯进⾏渲染(当然也可以像上⾯⼀样直接在home中引⼊element布局容器)
9.运⾏ npm run serve
10.下⾯展⽰以下效果

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。