nodejs(6):nodejs使用 vue + element 开发一个CURD (1)

版权声明:本文为博主原创文章,未经博主允许不得转载。博主地址:http://blog.csdn.net/freewebsys https://blog.csdn.net/freewebsys/article/details/80934134

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/80934134
nodejs分类:
https://blog.csdn.net/freewebsys/article/category/6904116

博主地址是:http://blog.csdn.net/freewebsys

1,关于element


研究了几个项目之后慢慢的明白了。nodejs。
使用 cnpm 下载的是压缩zip 文件速度快。而且是国内的镜像。
cnpm install 是安装依赖的文件。cnpm install -S element-ui,是下载eelement的组件到 node_modules 文件夹下面,然后就可以使用了。
其中的 package.json 是依赖文件。

项目参考:
https://taylorchen709.github.io/vue-admin/#/table
但是这个项目的vue 和 element 都不是新的,有些功组件是自己写的。
没有用到 el的布局,啥的。

2,搭建admin布局


布局是 顶部header 走侧菜单,右侧内容的。

<el-container>
  <el-header>Header</el-header>
  <el-container>
    <el-aside width="200px">Aside</el-aside>
    <el-main>Main</el-main>
  </el-container>
</el-container>

主要就是 el-header el-aside el-main 三个组件配合 el-container 进行展示。

然后是菜单使用

<el-aside width="200px">
        <el-menu :default-openeds="['1']">
        <el-submenu index="1">
            <template slot="title"><i class="el-icon-message"></i>用户管理</template>
            <el-menu-item-group>
                <el-menu-item index="1-1">用户管理</el-menu-item>
                <el-menu-item index="1-2">角色管理</el-menu-item>
                <el-menu-item index="1-2">权限管理</el-menu-item>
            </el-menu-item-group>
        </el-submenu>
        </el-menu>
    </el-aside>

3,全部代码


<template slot-scope="Home">
  <el-container style="height: 100%; border: 1px solid #eee">

      <el-header style="text-align: right; font-size: 16px;background-color:#409EFF;color:#fff;">
      <el-dropdown>
        <i class="el-icon-setting" style="margin-right: 15px"></i>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>查看</el-dropdown-item>
          <el-dropdown-item>新增</el-dropdown-item>
          <el-dropdown-item>删除</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <span>张三</span>
    </el-header>

    <el-container>
    <el-aside width="200px">
        <el-menu :default-openeds="['1']">
        <el-submenu index="1">
            <template slot="title"><i class="el-icon-message"></i>用户管理</template>
            <el-menu-item-group>
                <el-menu-item index="1-1">用户管理</el-menu-item>
                <el-menu-item index="1-2">角色管理</el-menu-item>
                <el-menu-item index="1-2">权限管理</el-menu-item>
            </el-menu-item-group>
        </el-submenu>
        </el-menu>
    </el-aside>

    <!-- 主界面 -->
    <el-main>

        <el-col>
            <el-button size="small" type="primary" @click="handleNew">增加</el-button>
        </el-col>

        <el-table :data="tableData" style="width: 100%;">
          <el-table-column prop="date" label="日期" width="140"/>
          <el-table-column prop="name" label="姓名" width="120"/>
          <el-table-column prop="address" label="地址"/>
          <el-table-column label="操作" width="150">
              <template slot-scope="scope">
                <el-button type="primary" size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                <el-button type="danger" size="mini" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
              </template>
          </el-table-column>
        </el-table>

         <el-col style="text-align:right;">
            <el-pagination
            background
            layout="prev, pager, next"
            :total="1000">
            </el-pagination>
        </el-col>
    </el-main>
    </el-container>

<el-dialog title="用户编辑" :visible.sync="dialogVisible" width="600">
  <el-form label-width="80px" ref="addForm">
                <el-form-item label="日期" prop="name">
                    <el-date-picker type="date" placeholder="选择日期"></el-date-picker>
                </el-form-item>
                <el-form-item label="姓名" prop="name">
                    <el-input auto-complete="off"></el-input>
                </el-form-item>
        <el-form-item label="地址" prop="name">
                    <el-input auto-complete="off"></el-input>
                </el-form-item>
            </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
</el-dialog>


 </el-container>
</template>

<style>
  .el-header {
    background-color: #B3C0D1;
    color: #333;
    line-height: 60px;
  }
  .el-aside {
    color: #333;
  }
</style>

<script>
  export default {
    name: 'Home',
    data() {
      const item = {
        date: '2018-06-01',
        name: '张三',
        address: '北京市 地球大厦 12345 号'
      };
      return {
        tableData: Array(10).fill(item),
        dialogVisible: false,//界面是否显示
      }
    },
    methods: {
        //删除
            handleNew: function (index, row) {
                this.dialogVisible = true;
      },
      handleEdit: function (index, row) {
                this.dialogVisible = true;
      },
      handleDelete: function (index, row) {
        console.log("delete ");
        this.$confirm('确认删除该记录吗?', '提示', {
                    type: 'warning'
                }).then(() => {

                }).catch(() => {

                });
      },
    }
  };
</script>

效果:

弹出窗口

分页按钮

4,总结


vue 这种组件开发的模式非常的方便,写代码就像配置 xml 一样。
非常严格的参数,有统一的标准,前端然后让开发web变得非常的简单方便。之前需要修改html 然后使用 jquery 操作,现在看来确实比较原始了。
直接通过组件化开发效率提高美化多了,肯定是趋势。

本文的原文连接是:
https://blog.csdn.net/freewebsys/article/details/80934134

博主地址是:http://blog.csdn.net/freewebsys

猜你喜欢

转载自blog.csdn.net/freewebsys/article/details/80934134