Vue使用方法记录 & Echars 库使用方法记录:

Vue常用方法记录:

生命周期相关:

created ()  {
},

mounted :function(){
  this.$nextTick(function () {
  });
 },

updated () {
},

路由相关:

this.$router.push({ path: '/invite' , query:{
    qrUrl : this.qrUrl
}});

this.$router.replace({ path: '/invite' , query:{
    qrUrl : this.qrUrl
}});

this.$route.query.qrUrl;

beforeRouteEnter(to, from, next) {
        next(vm => {
            if (
                from.path == '/account/success' 
            ) {
                location.href = location.href.split('#')[0] + '#/account/apply-list';
            }
        })
},

// 动态路由:路由的路径是 /report/business-report/1234567 可以动态变化,但是跳转的文件只是一个vue文件,
{
    path: '/report/business-report/:id',
    meta: {
      title: '业务报表'
    },
    component: (resolve) => require(['@/views/report/business-report.vue'], resolve)
  }
// 在动态路由间切换时不会重新创建该vue文件(不会再走created 、mounted),想要知道路由切换需要监听路由变化:

watch: {
  '$route': function (newValue) {
      // 该方法只能监听动态路径间的变化, 第一次进入该页面不会走
   }
},

空页面:

<template>
  <div class="main">

  </div>
</template>

<script>
export default {
  components: {
  },
  props: {
  },
  watch: {
  },
  data () {
    return {
    }
  },
  created () {
  },
  mounted () {
  },
  methods: {
  },
  filters: {
  }
}
</script>

<style scoped>
</style>

组件内嵌套内容的方法:

// 子组件:(核心是使用 slot 标记子组件名称)
<template is="parent-scroller">
    <scroller class="scroller">
        <refresh class="refresh" @refresh="onrefresh" @pullingdown="onpullingdown" :display="refreshing ? 'show' : 'hide'">
          <text class="indicator">正在刷新 ...</text>
        </refresh>
        <slot name='scroller-content'></slot>
        <loading class="loading" @loading="onloading" :display="showLoading">
         <text class="indicator">正在加载 ...</text>
       </loading>
    </scroller>
</template>

// 父组件 :(核心是使用slot添加内容)
<template>
  <div class="wrapper">
    <image src="/src/assets/images/travels/qy_background.png" class="background-image"></image>
    <scroller-list
      v-on:onrefresh='onrefresh'
      v-on:onpullingdown='onpullingdown'
      v-on:onloading='onloading'>
      <div slot='scroller-content'>
        <div class="title">
          <image src="/src/assets/images/travels/qy_title.png" class="title-image"></image>
        </div>
        <list-cell v-for="dataItem in lists"
          :dataItem='dataItem'
          :key='dataItem.id'>
        </list-cell>
      </div>
    </scroller-list>
  </div>
</template>

打包加速:

npm i -D happypack

npm install webpack-parallel-uglify-plugin --save

const ParallelUglifyPlugin = require('webpack-parallel-uglify-plugin')
const HappyPack = require('happypack')
const os = require('os')
const happyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length })

// prod.conf.js 中
plugins: [
    new ParallelUglifyPlugin({
      cacheDir: '.cache/',
      uglifyJS: {
        output: {
          comments: false
        },
        compress: {
          warnings: false
        }
      }
    }),
  new HappyPack({
    // 用id来标识 happypack处理那里类文件
    id: 'happyBabel',
    // 如何处理  用法和loader 的配置一样
    loaders: [{
      loader: 'babel-loader?cacheDirectory=true'
    }],
    // 共享进程池
    threadPool: happyThreadPool,
    // 允许 HappyPack 输出日志
    verbose: true
  })
  ]

module: {
    rules: [{
      test: /\.js$/,
      // 把对.js 的文件处理交给id为happyBabel 的HappyPack 的实例执行
      loader: 'happypack/loader?id=happyBabel',
      // 排除node_modules 目录下的文件
      exclude: /node_modules/
    }]
  }

// 对应库可以去npm看下使用方法~

常用方法:

//过滤器
filters: {
},
//监听器
watch: {
    value: function (newValue) {

    },
}
//标签相关
v-for='(item, index) in array'
:class="{'charts-selected': chartSelectIndex === item.index, 'charts-unselected': chartSelectIndex !== item.index}"

<customfather v-on:clild-tell-me-something='listeToMyBoy'></customfather>
this.$emit('clild-tell-me-something','回家吃饭')

this.outCallData.splice(index, 1, item) // 假装更改数组数据 强制更新dom

微信端vue项目跳转HTML文件时返回会不刷新vue界面方法(包括路由),这样会导致微信分享不受控制,该问题只出现于 iOS (webview返回层缓存导致),解决方法:

var u = navigator.userAgent
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)
if (isiOS) {
  window.addEventListener('pageshow', function (e) {
    if (e.persisted) {
      window.location.reload()
    }
  })
}

单页面引入<script>

参考

var script = document.createElement('script');  
    script.type = 'text/javascript';  
    script.src = 'http://api.map.baidu.com/api?v=2.0&ak=ak&callback=init';  
    script.onerror = reject;  
    document.head.appendChild(script);  

Echars 库使用方法记录:

error:there is a chart instance already initialized on the dom

在同一界面多个图表展示,如果只有一个echarts对象时会报这个错误. 因为dom渲染时找不到对应标签,可能dom渲染和echarts旋转的先后出了问题.
解决方法:

updated () {
    //在update中去重新加载echarts的option
     this.currentChart = echarts.init(document.getElementById(chartId));
     this.currentChart.setOption(chartOption);
}
warning:There is a chart instance already initialized on the dom.

如果该echarts表已经存在再重新init时会报这个警告
解决方法:

//在init方法前判断是否dom中已经存在,若存在则dispose()
var oldChart = echarts.getInstanceByDom(document.getElementById(chartId));
 if (oldChart) {
    oldChart.dispose();
}
this.currentChart = echarts.init(document.getElementById(chartId));
this.currentChart.setOption(chartOption);
option 相关解释
chartOption = {
    //鼠标滑过时展示的详细数据相关设置
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            crossStyle: {
                color: '#999'
            }
        }
    },
    //表格两边的留白距离
    grid :[
       {
            left:"70px",
            right:'70px'
        }
    ],
    //表格顶部显示的数据分类
    legend: {
        data:['蒸发量','降水量','平均温度']
    },
    //X坐标
    xAxis: [
        {
            type: 'category',
            data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
            axisPointer: {
                type: 'shadow'
            },
            offset:10//X轴单位名称上下编译坐标
        }
    ],
    //Y坐标
    yAxis: [
        {
            type: 'value',
            name: '水量',
            min: 0, //最小值
            max: 250, //最大值
            interval: 50, //单位长度
            minInterval: 1,//坐标轴最小间隔大小
            axisLabel: {
                //坐标单位显示格式化
                formatter: '{value} 万'
            },
            splitLine: {
                //是否显示横线(平行于X轴对应Y值得线)
                show: false
            },
        },
        {
            type: 'value',
            name: '温度',
            min: 0,
            max: 25,
            interval: 5,
            axisLabel: {
                formatter: '{value} 个'
            },
            splitLine: {
                show: false
            },
        }
    ],
    //数据配置
    series: [
        {
            name:'蒸发量',
            type:'bar',
            // stack:'总量', //是否累加数据(数据堆叠,同个类目轴上系列配置相同的stack值后,后一个系列的值会在前一个系列的值上相加。)
            data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
            //在图上显示数值
            label: {
                normal: {
                    show: true,
                    position: 'insideTop'
                }
            },
            //图的颜色等风格设置
            itemStyle: {
                normal: {
                    color : '#ff8a00'
                }
            }
        },
        {
            name:'降水量',
            type:'bar',
            // stack:'总量',
            data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
            label: {
                normal: {
                    show: true,
                    position: 'insideTop'
                }
            },
            itemStyle: {
                normal: {
                    color : '#2c80e9'
                }
            }
        },
        {
            name:'平均温度',
            type:'line',
            yAxisIndex: 1,//多个Y轴时通过这个设置对应Y轴
            data:[2.0, 2.2, 3.3, 4.5, 6.3, 10.2, 20.3, 23.4, 23.0, 16.5, 12.0, 6.2],
            label: {
                normal: {
                    show: true,
                    position: 'top'
                }
            },
            itemStyle: {
                normal: {
                    color : 'red'
                }
            }
        }
    ]
};
效果图
雷达图例子
this.chartOption = {
        radar: [{
          name: {
            fontSize: 24 // 顶点字体大小 不能设置 radio 否则不能生效
          },
          splitLine: {
            lineStyle: {
              color: '#00aaff' // 每一圈的边界颜色
            }
          },
          axisLabel: {
            inside: true
          },
          axisLine: {
            lineStyle: {
              color: '#00aaff' // 半径线颜色
            }
          },
          splitArea: {
            areaStyle: {
              // color: ['#00aaff', '#0099ff', '#00aaff', '#0099ff', '#00aaff'] // 每一圈的颜色
            }
          },
          indicator: [
              {text: '健康风险', max: 100, color: '#099aed'}, // 选中颜色
              {text: '驾乘风险', max: 100},
              {text: '固定资产', max: 100},
              {text: '财务风险', max: 100},
              {text: '赡养抚养', max: 100},
              {text: '出行意外', max: 100}
          ]
        }],
        series: [{
          type: 'radar',
          data: [{
            value: [60, 73, 85, 40, 50, 100],
            areaStyle: {
              normal: {
                opacity: 0.8, // 图表透明度
                color: '#6397ff' // 图表颜色
              }
            },
            lineStyle: {
              color: '#6397ff' // 图表边框颜色
            },
            label: {
              normal: {
                show: true,
                color: '#6397ff', // 顶点数字颜色
                fontSize: 24,  // 顶点数字大小
                formatter: function (params) {
                  return params.value
                }
              }
            }
          }]
        }]
      }
雷达图效果
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,219评论 4 362
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,363评论 1 293
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 108,933评论 0 243
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,020评论 0 206
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,400评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,640评论 1 219
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,896评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,597评论 0 199
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,327评论 1 244
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,581评论 2 246
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,072评论 1 261
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,399评论 2 253
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,054评论 3 236
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,083评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,849评论 0 195
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,672评论 2 274
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,585评论 2 270

推荐阅读更多精彩内容