<el-table :data="tableData" border>
<el-table-column
v-for="item in tableColumns"
:key="item.prop"
:prop="item.prop"
:label="item.label"
>
</el-table-column>
</el-table>
data () {
return {
tableData: [],
tableColumns: [ // 已知表头
{
label: '日期',
prop: 'tDate'
},
...
]
}
},
methods: {
get_tabledata () {
const self = this
var res = {
status: 200,
message: 'success',
data: {
addColumn: [ // 后台动态数据添加到表头
{
prop: 'groupMoney1',
label: '渠道组1'
},
...
],
inData: [
{
tDate: '2020-11-01',
sumCost: 12312313,
sumMoney: 12312313,
sumDAU: 2333,
IosMoney: 11111,
androidMoney: 23933,
groupMoney1: 22222,
groupMoney2: 67555
},
...
]
}
}
self.tableData = res.data.inData
self.tableColumns = [...self.tableColumns,...res.data.addColumn] // 合并表头数组
}
},
http://html2canvas.hertzen.com/getting-started
<!--安装插件-->
npm install html2canvas
<!--在script标签中引入实例-->
import html2canvas from 'html2canvas';
<!--在button点击事件或者created事件中画图-->
html2canvas(document.body).then(function(canvas) {
document.body.appendChild(canvas);
});
<!--项目中使用-->
<Button type="primary" ghost @click="explain_handle">输出分析报告</Button>
explain_handle () {
this.explain_modal = !this.explain_modal
html2canvas(document.getElementById('table_box')).then(function (canvas) {
document.getElementById('img_box').appendChild(canvas)
})
},
/**
* @description 用于将获取yyyy-mm-dd格式的当前时间,且是1号
*/
export const month_now = () => {
var d = new Date()
var datetime = ''
if (d.getMonth() < 9) {
datetime = d.getFullYear() + '-0' + (d.getMonth() + 1) + '-01'
} else {
datetime = d.getFullYear() + '-' + (d.getMonth() + 1) + '-01'
}
return datetime
}
created () {
const self = this
// 这里的空格''使得生成的中国标准时间的时分秒是00:00:00
const now = new Date(month_now() + ' ')
const nowdate = [now]
// monthtime是时间选择器v-model的时间变量
self.monthtime = nowdate
console.log(nowdate)
self.month_time = month_handle(self.monthtime)
}
// console命令
npm i -D live-server
// 修改package.json
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
// 增加一个start命令
"start": "live-server ./dist -o",
"lint": "vue-cli-service lint"
},
// 可以直接写'element-ui'是因为框架就是这么抛出的,用element-ui代表了指定路径,可以去node-modules下面去看看有没有一个名为element-ui的文件夹
// { Loading }这种方式是ES6的解构赋值
import { Loading } from 'element-ui'
Vue.use(Loading.directive)
<el-table
v-loading="tableloading"
:data="tableData"
style="width: 100%;"
>
// 默认值
data () {
return {
tableloading: false,
// 开始请求的时候设置为true,加载动画开始
getYYReportListByGroup (req_obj) {
this.tableloading = true
// 拿到数据之后又设置为false,停止加载
this.tableloading = false
// monthHandle是方法名,也可以传参
<el-table-column prop="date" label="月份" fixed min-width="82px">
<template slot-scope="scope">
<span>{{ scope.row.date | monthHandle }}</span>
</template>
</el-table-column>
// cell是默认第一个参数(scope.row.date),传过来的参数默认在第二个位置
<script>
export default {
name: 'groupgame_day',
components: {},
data () {
return {}
},
filters: {
monthHandle (cell) {
return cell.split('-')[1] + '月'
}
},
// 日期到时月,X月
export function monthHandle (val) {
if (!val) return val
return val.split('-')[1] + '月'
}
import * as Filter from '@/common/js/filters'
// 全局过滤器
for (const key in Filter) {
Vue.filter(key, Filter[key])
}
peerDependences 强制依赖,vue-echarts强制依赖vue(几十k)和echarts(比较大)
关于echarts和vue-echarts
区分cli2和cli3
安装和使用
https://github.com/ecomfe/vue-echarts/blob/master/README.zh_CN.md
// 全局引入
import VueECharts from 'vue-echarts' // 在 webpack 环境下指向 components/ECharts.vue
Vue.component('v-chart', VueECharts)
//-----自己抽的组件中按需引入------
// 手动引入 ECharts 各模块来减小打包体积
import ECharts from 'vue-echarts'
import 'echarts/lib/chart/bar'
import 'echarts/lib/component/tooltip'
// 以上具体模块的路径可以在node modules里面去看
components: {
'v-chart': ECharts
},
没有显示的原因
<div class="comBox">
<div v-for="(item,idx) in com_arr" :key="item.id" class="comcell" :class="{'selcomcell': item.check}" @click="selcom_handle()">
<span>{{item.name}}</span>
<Icon type="md-close-circle" @click.stop="close_com(idx)" />
</div>
<button type="text" class="add-btn" @click="addcom_handle()">+添加</button>
</div>
计算属性和函数的区别
http://v1.iviewui.com/components/upload
<Upload action="" :before-upload="preUpload">
<el-image class="m-image-box" :src="base64Image" fit="scale-down"></el-image>
</Upload>
preUpload (file) {
const {size, name, type} = file
if (!['image/png', 'image/jpeg'].includes(type)) {
this.$Message.error({
closable: true,
duration: 5,
content: `上传的文件名 ${name} 格式错误!`
})
return false
}
if (size > 300 * 1024) {
this.$Message.error({
closable: true,
duration: 5,
content: `上传的文件名 ${name} 超过限制大小`
})
return false
}
this.uploadFile(file)
return false
},
uploadFile (file) {
const reader = new FileReader()
const that = this
reader.readAsDataURL(file)
reader.onload = function (e) {
that.base64Image = this.result
that.file = file
}
},
request.class.js
series: [
{
name: '趋势',
type: 'line',
data: [],
smooth: true,
markLine: {
data: [
{type: 'average', name: '平均值'}
]
}
},
{
name: '模拟',
type: 'line',
data: [],
smooth: true,
markLine: {
/* 以下设置一行后,平均线就没有开始和结束标记了(即看不见箭头了) */
symbol: 'none',
data: [{
name: '平均线',
// 支持 'average', 'min', 'max'
type: 'average',
lineStyle: {
normal: {
color: 'green',
width: 2,
type: 'solid'
}
}
}]
}
}
]
yAxis: {
type: 'value',
splitLine: {
show: false
}
}
dataZoom: [
{
type: 'slider',
show: true,
xAxisIndex: [0],
start: 20,
end: 100
}
],
import 'echarts/lib/component/toolbox'
toolbox: {
feature: {
magicType: {
type: ['line', 'bar']
}
}
},