• element ui框架(第一个element ui程序)


    【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com】

            有了之前的nodejs和vue作为铺垫之后,后面就可以准备导入element ui库了。我们还是以一个demo的形式来完整说明,应该如何导入element ui库。

    1、创建test-elementui工程

            用管理员的账号打开cmd窗口,输入vue init ./webpack test-elementui。不出意外的话,就可以看到创建好的test-elementui的目录。

    1. C:\Users\feixiaoxing\Desktop\test>vue init ./webpack test-elementui
    2. ? Project name test-elementui
    3. ? Project description A Vue.js project
    4. ? Author feixiaoxing <feixiaoxing@163.com>
    5. ? Vue build standalone
    6. ? Install vue-router? Yes
    7. ? Use ESLint to lint your code? No
    8. ? Set up unit tests No
    9. ? Setup e2e tests with Nightwatch? No
    10. ? Should we run `npm install` for you after the project has been created? (recommended) no
    11. vue-cli · Generated "test-elementui".
    12. # Project initialization finished!
    13. # ========================
    14. To get started:
    15. cd test-elementui
    16. npm install (or if using yarn: yarn)
    17. npm run dev
    18. Documentation can be found at https://vuejs-templates.github.io/webpack

    2、安装好第三方库

            下面要做的,就是先安装好其他第三方库。

    1. cd test-elementui
    2. npm install

    3、继续安装element-ui库

    npm install element-ui -S

    4、确保element-ui已经安装上了

            如果安装没有问题,可以发现node-modules下面element-ui库已经安装好了。

    5、寻找src目录下面的main.js文件,添加相关内容,修改好的main.js如下所示

    1. // The Vue build version to load with the `import` command
    2. // (runtime-only or standalone) has been set in webpack.base.conf with an alias.
    3. import Vue from 'vue'
    4. import App from './App'
    5. import router from './router'
    6. // 添加elementui文件
    7. import ElementUI from 'element-ui';
    8. import 'element-ui/lib/theme-chalk/index.css';
    9. // 将ElementUI添加到vue里面
    10. Vue.use(ElementUI);
    11. Vue.config.productionTip = false
    12. /* eslint-disable no-new */
    13. new Vue({
    14. el: '#app',
    15. router,
    16. components: { App },
    17. template: '',
    18. render:h=>h(App) // 添加渲染
    19. })

            修改的地方主要有三处。第一处就是引入element-ui和index.css文件;第二处是将ElementUI添加到Vue中;第三处就是render渲染。上述三处都有中文说明,大家可以好好看一下。

    6、编译运行

    npm run dev

            输入上述命令之后,如果没有错误的话,就会产生相关的打印。比如像这样,

    1. DONE Compiled successfully in 29802ms 14:34:59
    2. I Your application is running here: http://localhost:8082

    7、第一次添加element代码

            默认工程显示的内容都是放在components/HelloWorld.vue下面,可以在上面做相关修改。注意,修改的时候,可以让console窗口一直打开,因为默认nodejs是支持动态修改的。修改后的HelloWorld.vue内容如下,

    1. <template>
    2. <div class="hello">
    3. <el-row>
    4. <el-button>默认按钮</el-button>
    5. <el-button type="primary">主要按钮</el-button>
    6. <el-button type="success">成功按钮</el-button>
    7. <el-button type="info">信息按钮</el-button>
    8. <el-button type="warning">警告按钮</el-button>
    9. <el-button type="danger">危险按钮</el-button>
    10. </el-row>
    11. </div>
    12. </template>
    13. <script>
    14. export default {
    15. name: 'HelloWorld',
    16. data () {
    17. return {
    18. msg: 'Welcome to Your Vue.js App'
    19. }
    20. }
    21. }
    22. </script>
    23. <!-- Add "scoped" attribute to limit CSS to this component only -->
    24. <style scoped>
    25. h1, h2 {
    26. font-weight: normal;
    27. }
    28. ul {
    29. list-style-type: none;
    30. padding: 0;
    31. }
    32. li {
    33. display: inline-block;
    34. margin: 0 10px;
    35. }
    36. a {
    37. color: #42b983;
    38. }
    39. </style>

    8、重新打开127.0.0.1:8082网页,不出意外,就可以相关的显示内容了,

             姑且不论美丑,只要看到这些按钮,至少说明element ui已经用起来了。后面就可以借助于node.js和vue进一步开发前端网站了。

    9、发布

            如果需要发布的话,那么直接输入npm run build即可。执行结束后,就会发现有一个dist目录,里面包含一个static目录和index.html文件。其中index.html就是入口文件,static下面包含了css、fonts、js三个目录,相关文件已经做了压缩和重新编码。

  • 相关阅读:
    SpringSecurity系列一:04 SpringSecurity 的默认用户是如何生成的?
    形态学 - 细化
    字体反爬积累知识
    基于改进樽海鞘群算法求解单目标优化问题
    VSCode激活conda虚拟环境遇到的问题处理方法
    响应式数据
    ETL数据转换工具类型与适用场景
    [附源码]java毕业设计基于新高考模式下的排课系统
    代码随想录49——动态规划:121买卖股票的最佳时机、122买卖股票的最佳时机II
    vr航天探索科普展vr航天科普亲子嘉年华
  • 原文地址:https://blog.csdn.net/feixiaoxing/article/details/126904992