SpingBoot + Vue + Element UI + Echarts 整合的小 Demo

SpingBoot + Vue + Element UI + Echarts 整合的小 DemoVue 工程创建 Vue 工程 (两种创建方式:vue ui 、手动初始化创建)安装 Element UI、axios 插件安装 Echarts 官网 https://echarts.apache.org/zh/index.html1、执行命令cnpm install echarts@4.9.0 --save2、main.js 中引入import echarts from 'echarts
摘要由CSDN通过智能技术生成

SpingBoot + Vue + Element UI + Echarts 整合的小 Demo

Vue 工程

1、执行命令

cnpm install echarts@4.9.0 --save

2、main.js 中引入

import echarts from 'echarts'
Vue.prototype.$echarts = echarts

3、代码

<template>
    <div id="myChart" :style="{width: '800px', height: '600px'}"></div>
</template>
<script>
    export default {
   
        name: 'Echarts',
        mounted(){
   
            // 基于准备好的dom,初始化echarts实例
            let myChart = this.$echarts.init(document.getElementById('myChart'))
            // 绘制图表
            myChart.setOption()  //一般从官网复制Option过来直接放到setOption()里面
        }
    }
</script>
  • App.vue
<template>
  <div id="app">
    <div id="nav">
      <router-link to="/add">添加数据</router-link> |
      <router-link to="/table">数据管理</router-link> |
      <router-link to="/pie">饼图</router-link> |
      <router-link to="/bar">柱状图</router-link>
    </div>
    <div style="border:0px solid red;width: 800px;height: 600px;margin-left: 366px;">
      <router-view/>
    </div>
  </div>
</template>
<template slot-scope="scope">
    <img :src="scope.row.icon" style="height: 70px"/>
</template>
=================================================================
<template>
  <el-table
    :data="tableData"
    border
    style="width: 100%">
    <el-table-column
      prop="icon"
      label="图片"
      width="160">
      <template slot-scope="liu">
        <img :src="liu.row.icon" style="height: 70px"/>
      </template>
    </el-table-column>

    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
		//传递参数把操作的此行对象传入  fruitDelete(scope.row)
        <el-button @click="fruitDelete(scope.row)" type="text" size="small">删除</el-button>
        <el-button @click="findFruit(scope.row)" type="text" size="small">编辑</el-button>
      </template>
        
    </el-table-column>
  </el-table>
</template>

<script>
export default {
   
    ===============
  methods: {
   
    findFruit (object) {
   
      this.$router.push('/edit?id=' + object.id) // 页面跳转到我们的edit页面带上id
        //let id = this.$route.query.id // 获取id 在edit页面中这样获取id
    },
    fruitDelete (row) {
    // 传入我们的数据 row
      let _this = this
      this.$confirm('是否确定要删除' + row.name + '?', '删除数据', {
   
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
    // 点击确定就进入这个回调中
        _this.$axios.delete('http://localhost:8181/fruit/delete/' + row.id).then(function (response) {
   
          if (response.data) {
   
            _this.$alert(row.name + '删除成功!', '删除数据', {
   
              confirmButtonText: '确定',
              callback: action => {
   
                // 跳转到/table
                location.reload() // 点击确定就执行这个  ---刷新页面
              }
            })
          }
        })
      }).catch(() => {
   
      })
    }

  },
    ======================
  // get 去请求  then 去回调
  // this 表示的vue对象,在回调中我们拿的是回调的对象  所以我们设置_this来表示全局的对象
  created () {
   
    let _this = this
    this.$axios.get('http://localhost:8181/fruit/list').then(function (response) {
   
      _this.tableData = response.data
    })
  },
    =====================
  data () {
   
    return {
   
      tableData: null
    }
  }
}
</script>

  • 数据校验
<template>
    <el-form ref="fruitRules" :model="fruit" :rules="rules" label-width="80px" class="demo-ruleForm" style="width: 600px">
        <!-- prop 就是跟我们的校验规则绑定的-->
        <el-form-item label="名称" prop="name">
            <el-input v-model="fruit.name"></el-input>
        </el-form-item>
        <el-form-item label="销量" prop="sale">
            <el-input v-model.number="fruit.sale"></el-input>
        </el-form-item>
        <el-form-item label="图片" prop="icon">
            <el-input v-model="fruit.icon"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onSubmit('fruitRules')">立即创建</el-button>
            <el-button @click="onSubmit1('form')">取消</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
    export default {
   
        name: "Add",
        data() {
   
            
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

早上真起不来!

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值