基于vue-cli3和element實現(xiàn)登陸頁面
1.先用vue-cli3創(chuàng)建一個項目
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.這里先擴(kuò)展一個小知識點
在package.json文件中找scripts下serve,在后面加上--open 可以實現(xiàn)運(yùn)行項目后自動打開瀏覽器
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.$message.error('登陸失敗'); } } } }; </script> <style lang="stylus" scoped></style>
由于只是簡單的展示以下 這里我們用一個死數(shù)據(jù)
這里簡單強(qiáng)調(diào)一下在邏輯層實現(xiàn)路由切換
<!-- router.push({path:'/foo'}) --> <!-- 聲明式導(dǎo)航 應(yīng)用于視圖層 --> <router-link to='/foo'>to foo</router-link> <router-view></router-view> <!-- 編程式導(dǎo)航 應(yīng)用于邏輯層--> <!-- router.push({path:'/foo'}) -->
到這里login頁面基本搭建完成
7.在router下的index.js中引入我們剛剛創(chuàng)建的login.vue
并對路徑作相應(yīng)改動
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", // 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: process.env.BASE_URL, routes }); export default router;
8.最后我們對home作一下簡單修飾。
博主這里在components中新建了一個組件helloworld并引入了element中的一個簡單的布局容器。
然后在home頁面引入helloworld對頁面進(jìn)行渲染(當(dāng)然也可以像上面一樣直接在home中引入element布局容器)
9.運(yùn)行 npm run serve
10.下面展示以下效果
總結(jié)
以上所述是小編給大家介紹的基于vue-cli3和element實現(xiàn)登陸頁面,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
element-plus dialog v-loading不生效問題及解決
這篇文章主要介紹了element-plus dialog v-loading不生效問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03Vue2響應(yīng)式系統(tǒng)之set和delete
這篇文章主要介紹了Vue2響應(yīng)式系統(tǒng)之set和delete,通過為對象收集依賴,將對象、數(shù)組的修改、刪除也變成響應(yīng)式的了,同時為用戶提供了和方法,下文詳細(xì)介紹需要的朋友可以參考一下2022-04-04vue鼠標(biāo)移入添加class樣式,鼠標(biāo)移出去除樣式(active)實現(xiàn)方法
今天小編就為大家分享一篇vue鼠標(biāo)移入添加class樣式,鼠標(biāo)移出去除樣式(active)實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-08-08vue-cli-service和webpack-dev-server的區(qū)別及說明
這篇文章主要介紹了vue-cli-service和webpack-dev-server的區(qū)別及說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10解讀element?el-upload上傳的附件名稱不顯示?file-list賦值
這篇文章主要介紹了解讀element?el-upload上傳的附件名稱不顯示?file-list賦值問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-10-10vue watch深度監(jiān)聽對象實現(xiàn)數(shù)據(jù)聯(lián)動效果
這篇文章主要介紹了vue watch深度監(jiān)聽對象實現(xiàn)數(shù)據(jù)聯(lián)動的方法,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2018-08-08vue內(nèi)置動態(tài)組件component使用示例小結(jié)
component是vue內(nèi)置組件,主要作用為動態(tài)渲染組件,這篇文章主要介紹了vue內(nèi)置動態(tài)組件component使用示例小結(jié),需要的朋友可以參考下2024-03-03