响应式布局
element -ui 找到layout布局 – 分栏间隔
gutter:间隔
span:列数
<el-row :gutter = "20">
<el-col :span = "6">
<div class="grid-content bg-purple"></div>
</el-col>
</el-row>
设置响应式
设置list数据
data() {
return {
list: [
{val:'13594', color:'#67ca3a', title:'最高可借金额'},
{val:'9833',color:'#ff6600',title: '回报率'},
{val:'8888',color:'#f56c6c',title: '业绩领跑'},
{val:'6666',color:'#409eff',title:'安稳底薪'} ]
}}}
先用for循环
<el-col :span="6" v-for = "(item,index) in list" :key = "index" >
<div class="dashboard-item" :style = {background: item.color}></div>
</el-col>
style下
.dashboard-item {
height:100px
}
响应式
<el-col :xl="6" :lg="6" :md="12" :sm="24" :xs="24"
v-for = "(item,index) in list" :key = "index" >
<div class="dashboard-item" :style = {background: item.color}>
{{item.title}}
{{item.value}}
</div>
</el-col>
设置样式
添加p
<p>{{item.title}}</p>
样式:
注意margin
.dashboard-item {
font-weight:bold;
color:#fff;
>p {
color: black;
height:40px;
margin:0px;
}}
动态数字
安装
npm install vue-count-to
开始,结束,持续时间
import countTo from 'vue-count-to';
components: {countTo}
<countTo :startVal="0" :endVal="item.val" :duration="3000">
echarts
<div class="echarts-box">
<div class="echart1"></div>
<div class="echart2"></div>
<div class="echart3"></div>
</div>
需要根元素,加一个div就可以
样式
高度塌陷
.echarts-box {
.chart1 {
width:100%;
}
.chart3,.chart2 {
width:50%;
height:400px
}
.echart2 {
float:left;
}
.chart3 {
float:right
}
overflow: hidden;
}
echarts官网
methods: {
initCharts() {
initCharts() {
let option1 = {
title: {
text: '第一个图表'
},
tooltip: {
trigger: 'axis'
},
legend: {
data: ['Email', 'Union Ads', 'Video Ads', 'Direct', 'Search Engine']
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
toolbox: {
feature: {
saveAsImage: {}
}
},
xAxis: {
type: 'category',
boundaryGap: false,
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
},
yAxis: {
type: 'value'
},
series: [
{
name: 'Email',
type: 'line',
stack: 'Total',
data: [120, 132, 101, 134, 90, 230, 210]
},
{
name: 'Union Ads',
type: 'line',
stack: 'Total',
data: [220, 182, 191, 234, 290, 330, 310]
},
{
name: 'Video Ads',
type: 'line',
stack: 'Total',
data: [150, 232, 201, 154, 190, 330, 410]
},
{
name: 'Direct',
type: 'line',
stack: 'Total',
data: [320, 332, 301, 334, 390, 330, 320]
},
{
name: 'Search Engine',
type: 'line',
stack: 'Total',
data: [820, 932, 901, 934, 1290, 1330, 1320]
}
]
};
let posList = [
'left',
'right',
'top',
'bottom',
'inside',
'insideTop',
'insideLeft',
'insideRight',
'insideBottom',
'insideTopLeft',
'insideTopRight',
'insideBottomLeft',
'insideBottomRight'
];
let app = {};
app.configParameters = {
rotate: {
min: -90,
max: 90
},
align: {
options: {
left: 'left',
center: 'center',
right: 'right'
}
},
verticalAlign: {
options: {
top: 'top',
middle: 'middle',
bottom: 'bottom'
}
},
position: {
options: posList.reduce(function (map, pos) {
map[pos] = pos;
return map;
}, {})
},
distance: {
min: 0,
max: 100
}
};
app.config = {
rotate: 90,
align: 'left',
verticalAlign: 'middle',
position: 'insideBottom',
distance: 15,
onChange: function () {
const labelOption = {
rotate: app.config.rotate,
align: app.config.align,
verticalAlign: app.config.verticalAlign,
position: app.config.position,
distance: app.config.distance
};
this.chart2.setOption({
series: [
{
label: labelOption
},
{
label: labelOption
},
{
label: labelOption
},
{
label: labelOption
}
]
});
}
};
const labelOption = {
show: true,
position: app.config.position,
distance: app.config.distance,
align: app.config.align,
verticalAlign: app.config.verticalAlign,
rotate: app.config.rotate,
formatter: '{c} {name|{a}}',
fontSize: 16,
rich: {
name: {}
}
};
let option2 = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
legend: {
data: ['Forest', 'Steppe', 'Desert', 'Wetland']
},
toolbox: {
show: true,
orient: 'vertical',
left: 'right',
top: 'center',
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar', 'stack'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
xAxis: [
{
type: 'category',
axisTick: { show: false },
data: ['2012', '2013', '2014', '2015', '2016']
}
],
yAxis: [
{
type: 'value'
}
],
series: [
{
name: 'Forest',
type: 'bar',
barGap: 0,
label: labelOption,
emphasis: {
focus: 'series'
},
data: [320, 332, 301, 334, 390]
},
{
name: 'Steppe',
type: 'bar',
label: labelOption,
emphasis: {
focus: 'series'
},
data: [220, 182, 191, 234, 290]
},
{
name: 'Desert',
type: 'bar',
label: labelOption,
emphasis: {
focus: 'series'
},
data: [150, 232, 201, 154, 190]
},
{
name: 'Wetland',
type: 'bar',
label: labelOption,
emphasis: {
focus: 'series'
},
data: [98, 77, 101, 99, 40]
}
]
};
let option3 = {
angleAxis: {},
radiusAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu'],
z: 10
},
polar: {},
series: [
{
type: 'bar',
data: [1, 2, 3, 4],
coordinateSystem: 'polar',
name: 'A',
stack: 'a',
emphasis: {
focus: 'series'
}
},
{
type: 'bar',
data: [2, 4, 6, 8],
coordinateSystem: 'polar',
name: 'B',
stack: 'a',
emphasis: {
focus: 'series'
}
},
{
type: 'bar',
data: [1, 2, 3, 4],
coordinateSystem: 'polar',
name: 'C',
stack: 'a',
emphasis: {
focus: 'series'
}
}
],
legend: {
show: true,
data: ['A', 'B', 'C']
}
};
this.chart1 = echarts.init(document.querySelector('.chart1'));
this.chart2 = echarts.init(document.querySelector('.chart2'));
this.chart3 = echarts.init(document.querySelector('.chart3'));
this.chart1.setOption(option1); // getOptions() 调试用的
this.chart2.setOption(option2);
this.chart3.setOption(option3);
},
import echarts from 'echarts'
this.chart1 = echarts.init( document.querySelector('.chart1'));
this.chart2 = echarts.init( document.querySelector('.chart2'));
this.chart3 = echarts.init( document.querySelector('.chart3'));
this.chart1.setOption(option1) // 取出
this.chart2.setOption(option2) // 取出
this.chart3.setOption(option3) // 取出
let option2
this.chart2
let app = {}
窗口问题
mounted() {
this.initCharts();
this.resizeCallback = this.resize.bind(this);
window.addEventListener('resize', this.resizeCallback )
},
beforeDestroy() {
window.removeEventListener('resize', this.resizeCallback )
}
methods:{
resize() {
this.chart1.resize();
this.chart2.resize();
this.chart3.resize();
}}
element-ui 避免使用2.15.9的版本
npm un element-ui -S && npm i element-ui@2.15.8
组件 GformCreator.vue
<template>
</template>
<script>
//jsx
export default {
props: {
conf:{
type:Object,
required:true
}},
render(h) {
return <h1> 123 </h1>
}}
</script>
将引入的4个组件提取出来,放到main.js里面,
注册组件
Vue.component(GAsideMenu.name,GAsideMenu);
新增加plugins的文件夹
引入的都放到这个里面
// Vue.component(GAsideMenu.name,GAsideMenu);
注册plugins在main.js
import plugins from '@/plugins'
Vue.use(plugins)
function install (Vue) {
Vue.component(GAsideMenu.name,GAsideMenu);
}
export default {
install
}
GformCreator组件
<template></template>
<script>
//jsx
export default {
name:'GformCreator',
props: {
conf: {
type: Object,
required: true
}
},
render(h) {
return <h1> 123 </h1>
}
}
</script>
create.vue
<template>
<GformCreator/>
</template>
新建文件:createFormConf.js
写数据和验证
export default Object.freeze({
title: '123',
items: [
[{ title: 'input', label: '用户名',colspan: 24, key: ' username' }],
[{ title: 'input', label: '密码',colspan: 24, key: ' password' }],
[{ title: 'input', label: '确认密码',colspan: 24, key: ' confirmPwd' } ]],
rules: {
username: [{ require: true }],
password: [{ require: true }]
}
})
create.vue下:
import createConf from './createFormConf'
export default {
data() {
return {
createConf
}}}
<GFormCreator :conf = "createConf">
</GFormCreator>
GformCreator.vue
解构
methods:{
renderRows(rows) {
return <h1> row </h1>
}
}
render(h) {
const { title,items:formItems } = this.conf;
return (
<div class="form-box">
<h1>{ title }</h1>
{/*表单*/}
<el-form label-width = "80px">
{ this.renderRows(items)}
</el-form>
// 按钮
<div class="btns">
{this.$slots.default}
</div>
</div>
)}}
style样式
.btn {
text-align:center
}
create.vue下
<GFormCreator ref="createForm" :conf = "createConf">
<template #default>
<el-button @click="doCreate" type = "primary ">创建管理员</el-button>
<el-button @click="doReset"> 重置 </el-button>
</template>
</GFormCreator>
methods : {
doCreate() {
this.$refs.createForm.submit((data => {
if(data) {
console.log('验证成功',data)
} else {
console.log('验证失败')
}})},
doReset() {
this.$refs.createForm.reset();
}}
GFormCreator.vue
submit() {
return '假数据'
},
reset() {
console.log('假重置')
}
normalize.css
清除浮动
.clear-fix ::after {
contemr:'';
height:0;
clear:both;
}
GformCreator.vue
renderRows(rows) {
return rows.map(rowArr => {
return
<el-row>
{this.renderColums()}
</el-row>
})}
renderItem() {
return <el-input> </el-input>
}
renderColums(columns) {
return columns.map(item => {
return
<el-col xl={6},lg={6},md={12},sm={24},xs={24}>
<el-form-item label={item.label}> {this.renderItem(item)} </el-form-item>
</el-col>
})
}
xl={item.colspan} lg={item.colspan}