在vue2项目中,使用element ui 的详细步骤

  1.  安装 Element UI:首先,你需要安装Element UI库。可以通过 npm 或 yarn 进行安装。在命令行中执行以下命令:
    npm i element-ui -S
  2. 导入 Element UI 组件:在项目的入口文件中(一般是 main.js)导入Element UI组件和样式。通常你需要导入整个库或者按需导入组件。

    如果你想要导入整个库,可以这样:

    import ElementUI from 'element-ui';
    import 'element-ui/lib/theme-chalk/index.css';
    Vue.use(ElementUI);
    

  3. 在组件中使用 Element UI 组件:现在你可以在你的Vue组件中使用Element UI提供的各种组件了。例如在组件中 使用菜单  

  4. 首先,创建菜单组件,在vue文件中创建一个新的组件来呈现菜单,

    <template>
      <div>
        <el-menu
          :default-active="activeIndex"
          mode="horizontal"
          @select="handleMenuSelect"
        >
          <el-menu-item index="1">菜单项1</el-menu-item>
          <el-menu-item index="2">菜单项2</el-menu-item>
          <el-menu-item index="3">菜单项3</el-menu-item>
        </el-menu>
        <!-- <div v-if="activeIndex">{{ activeIndex }}</div> -->
      </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
          activeIndex: "",
        };
      },
      methods: {
        handleMenuSelect(index) {
          if (index === "1") {
            this.$router.push({ path: "/about" }); // 点击第一个菜单项时跳转到首页
          }
          if (index === "2") {
            this.$router.push({ path: "/" }); // 点击第一个菜单项时跳转到首页
          }
          this.activeIndex = index;
        },
      },
    };
    </script>
    
    <style>
    /* 可以根据需要添加样式 */
    </style>

  5. 在app.vue 中 使用菜单组件

  6. 这儿我是做了一个菜单之后显示的内容 , 加了一个 跳转路由和 路由视口

这样一个简单的使用就完成了 ,其实element ui 还有很多细节的地方 ,未来的地方一点点填充吧 。加油! 

  • 5
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值