Vue 組件庫 Element 腳手架 入門教程


https://blog.csdn.net/u012359995/article/details/79702157

前提是安裝了nodejs(6.0+),npm 
驗證安裝成功 node –version 
npm –version

 

Element官網地址:
http://element-cn.eleme.io/#/zh-CN

Element 腳手架 代碼git地址:
https://github.com/ElementUI/element-starter.git

git clone下來后,進入element-starter目錄

關於yarn的說明請看yarn的安裝與使用 - CSDN博客

npm install -g yarn

 

命令行進入element-starter目錄下,執行:npm install

等待初始化完成,然后再執行 npm run dev

 

在瀏覽器打開 http://127.0.0.1:8010

 

 

 

對應的代碼為,在src目錄下的App.vue文件,

<template>
  <div id="app">
    <img src="./assets/logo.png">
    <div>
      <el-button @click="startHacking">Start</el-button>
    </div>
  </div>
</template>

<script>
export default {
  methods: {
    startHacking () {
      this.$notify({
        title: 'It works!',
        type: 'success',
        message: 'We\'ve laid the ground work for you. It\'s time for you to build something epic!',
        duration: 5000
      })
    }
  }
}
</script>

<style>
#app {
  font-family: Helvetica, sans-serif;
  text-align: center;
}
</style>

 

開始寫一個自己的頁面
這里要用到路由,所以需要執行下面的命令安裝一下

npm install vue-router --save
修改App.vue文件,添加一個路由的標簽

<template>
<div id="app">
<transition name="fade" mode="out-in">
<router-view></router-view>
</transition>
</div>
</template>

<script>
export default {
methods: {
startHacking () {
this.$notify({
title: 'It works!',
type: 'success',
message: 'We\'ve laid the ground work for you. It\'s time for you to build something epic!',
duration: 5000
})
}
}
}
</script>

<style>
#app {
font-family: Helvetica, sans-serif;
text-align: center;
}
</style>

 

在src目錄下的新建一個名為 routes.js 的文件,內容如下:

import Login from './views/Login.vue'

let routes = [
{
path: '/login',
component: Login,
name: '',
hidden: true
}
];

export default routes;

 

在src目錄下的新建一個名為 views 的文件夾,在該文件夾下再新建一個名為Login.vue的文件,內容如下:

<template>

  <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" label-position="left" label-width="0px" class="demo-ruleForm login-container">
    <h3 class="title">系統登錄</h3>
    <el-form-item prop="account">
      <el-input type="text" v-model="ruleForm2.account" auto-complete="off" placeholder="賬號"></el-input>
    </el-form-item>
    <el-form-item prop="checkPass">
      <el-input type="password" v-model="ruleForm2.checkPass" auto-complete="off" placeholder="密碼"></el-input>
    </el-form-item>
    <el-checkbox v-model="checked" checked class="remember">記住密碼</el-checkbox>
    <el-form-item style="width:100%;">
      <el-button type="primary" style="width:100%;" @click.native.prevent="handleSubmit2" :loading="logining">登錄</el-button>
      <!--<el-button @click.native.prevent="handleReset2">重置</el-button>-->
    </el-form-item>
  </el-form>
</template>

<script>

  export default {
    data() {
      return {
        logining: false,
        ruleForm2: {
          account: 'admin',
          checkPass: '123456'
        },
        rules2: {
          account: [
            { required: true, message: '請輸入賬號', trigger: 'blur' },
            //{ validator: validaePass }
          ],
          checkPass: [
            { required: true, message: '請輸入密碼', trigger: 'blur' },
            //{ validator: validaePass2 }
          ]
        },
        checked: true
      };
    },
    methods: {
      handleReset2() {
        this.$refs.ruleForm2.resetFields();
      },
      handleSubmit2(ev) {
        var _this = this;
        this.$refs.ruleForm2.validate((valid) => {

        });
      }
    }
  }

</script>
<style >
  .login-container {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 40px auto;
      text-align: center;
      color: #505458;
    }
    .remember {
      margin: 0px 0px 35px 0px;
    }
  }
</style>

 

修改 main.js文件,

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

import VueRouter from 'vue-router'
import routes from './routes'

Vue.use(ElementUI)
Vue.use(VueRouter)

const router = new VueRouter({
  routes
})

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

執行 npm run dev

啟動完畢后,在瀏覽器輸入http://127.0.0.1:8010/#/login

即可看到下面的頁面

 

 

打包

npm run build
  • 1

在src同級目錄下會生成一個名為dist的文件夾,

這里寫圖片描述

打開index.html,后面跟上#/login即可看到手寫的頁面

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM