vue使用ElementUI搭建精美页面入门

发布时间:2023年12月24日

ElementUI简直是css学得不好的同学的福音

ElementUI官网:

?Element - The world's most popular Vue UI framework

安装

在vue文件下,用这个命令去安装Element UI。

npm i element-ui -S

step1\先切换到vue的目录下去,注意这里面的WARN不是报错。红框里的内容提示我们此时添加了九个包。

然后在node_modules里能看到element-ui的安装包

引入

在main.js中引用代码,在原有代码基础上再添加这三行即可:

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(ElementUI);

然后新建一个名叫Element.vue的页面

然后页面中输入以下代码:

<template>
  <div>
    <el-row>
      <el-col :span="12">
        <div style="width:100%;height:300px;background-color:dodgerblue"></div>
      </el-col>
      
      <el-col :span="12">
        <div style="width:100%;height:300px;background-color:red"></div>
        
      </el-col> 
       
    </el-row>
    
  </div>
  
  
</template>

此时启动该文件的运行有以下几种方法:

1、在我博客《vue2入门》结尾处写了如何配置启动的快捷方式

2、在终端输入命令运行:

MacBook-Pro-2 vue % npm run serve

看到这样的结果就算是运行成功了

而此时我们还要添加路由,才能访问到Element.vue

在router/index.js文件const routes下添加路由:

 {
    path: '/element',
    name: 'Element',
    // 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/Element.vue')
  }

然后直接在地址栏里加上/Element

然后自己多去官网看文档就好了。

文章来源:https://blog.csdn.net/weixin_49393290/article/details/135165354
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。