引入echarts

    1. import * as echarts from 'echarts'

    创建function
    image.png
    定义echarts的Id
    image.png
    设置配置
    image.png
    说一下配置吧,
    background,series,title,需要说的是series
    clockWise:伸缩动画顺时针
    radius:设置大小,设置宽度
    itemStyle:图形样式
    shadowColor:阴影颜色
    shadowBlur:阴影模糊度,类似于特效image.png
    label:标签
    labelline:折线偏移量
    hoverAnimation:hover动画
    normal/emphasis:两个条形的样式

    1. yourchart.setOption({
    2. backgroundColor: '#fff',
    3. title: [{
    4. text:'今日目标',
    5. left: '45%',
    6. top: '10%',
    7. textAlign: 'center',
    8. textStyle: {
    9. fontWeight: 'normal',
    10. fontSize: '18',
    11. color:'#AAAFC8',
    12. textAlign: 'center',
    13. },
    14. }],
    15. //第一个图表
    16. series: [
    17. {
    18. name: '今日目标',
    19. type: 'pie',
    20. clockWise: false,
    21. radius: [30, 40],
    22. itemStyle: {
    23. normal: {
    24. color:"#389af4",
    25. shadowColor: '#389af4',
    26. shadowBlur: 0,
    27. label: {
    28. show: false
    29. },
    30. labelLine: {
    31. show: false
    32. },
    33. }
    34. },
    35. hoverAnimation: false,
    36. center: ['50%', '65%'],
    37. data: [{
    38. value: branch,
    39. label: {
    40. normal: {
    41. formatter: function(params){
    42. return params.value+'%';
    43. },
    44. position: 'center',
    45. show: true,
    46. textStyle: {
    47. fontSize: '20',
    48. fontWeight: 'bold',
    49. color: '#389af4'
    50. }
    51. }
    52. },
    53. }, {
    54. value: 100 -branch,
    55. name: 'invisible',
    56. itemStyle: {
    57. normal: {
    58. color: '#dfeaff'
    59. },
    60. emphasis: {
    61. color: '#dfeaff'
    62. }
    63. }
    64. }]
    65. }
    66. ]
    67. }
    68. )

    有一个传值的问题是,我的步数是在methods里更改了步数,那么,这个方法要放在created里执行,要比子组件的mounted早执行,否则传值只能传到第一个初始的值,就是NAN空值
    image.png
    关于组件传值:
    使用的方法是父传子:从父组件直接获取到子组件(还可以传方法)

    1. var branch =parseInt(this.$parent.steps)
    2. //this.$parent.steps

    还有一种父传子的方法就是,image.png
    父组件写::notice传值,子组件写image.pngprops放在data外面
    子传父:

    1. //子组件
    2. data(){
    3. return{
    4. childValue: '我是子组件的数据'
    5. }
    6. //methods
    7. this.$emit('childByValue', this.childValue)
    8. //父组件
    9. //v-on监听
    10. <Steps v-on:childByValue="childByValue"></Steps>
    11. //methods
    12. childByValue: function (childValue) {
    13. // childValue就是子组件传过来的值
    14. this.name = childValue
    15. alert(this.name);
    16. },

    image.png
    image.png
    优化后的界面
    image.png