Vue 使用 ElementUI 构建表格 --柚子真好吃

Vue 使用 ElementUI 构建表格 --柚子真好吃

注:该文章内容在搭建好vue-cli的环境下进行。

文章代码参考:https://blog.csdn.net/liaoxuewu/article/details/81184821

一、安装Element

  • 登录element官网查看教程:https://element-angular.faas.ele.me/guide/install

  • npm安装,找到自己的项目目录,如下图。
    在这里插入图片描述

  • 开启命令行进行安装

     npm install element-ui -S
    
  • 在main.js中进行配置,代码如下

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.config.productionTip = false

/* eslint-disable no-new */
Vue.use(ElementUI);

new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})

二、前台代码

<div class="tableMain">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="id" label="ID" width="180">
        </el-table-column>
        <el-table-column prop="name" label="用户名" width="180">
        </el-table-column>
        <el-table-column prop="city" label="城市" width="180">
          <template scope="scope">
            <el-select v-model="scope.row.city" placeholder="请选择">
              <el-option v-for="item in cityList" :key="item.name" :label="item.name" :value="item.name">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="address" label="地址">
        </el-table-column>
        <el-table-column label="操作">
          <template scope="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑
            </el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

数据可先自己定义,代码如下

export default {
  name:"basetable",
  data() {
    return {
      loading: true,
      tableData: [{
        id: '1001',
        name: 'Tom',
        region: '男',
        address: '猫窝',
        city: ''

      }, {
        id: '1002',
        name: 'Jerry',
        region: '女',
        address: '鼠洞',
        city: ''
      }, {
        id: '1003',
        name: 'Spike',
        region: '男',
        address: '狗窝',
        city: ''
      },],
      cityList: [
        { name: '猫窝' },
        { name: '鼠洞' },
        { name: '狗窝' },
      ],
      dialogFormVisible: false,
      formLabelWidth: '80px',
      }

注:属性名要一一对应上。

这样我们运行一下
在这里插入图片描述
网页中运行的效果如下
在这里插入图片描述
这样的话我们的数据就展示到表格中了。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是小金毛

可怜可怜孩子吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值