Vue使用方法記錄 & Echars 庫使用方法記錄:

Vue常用方法記錄:

生命周期相關(guān):

created ()  {
},

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

updated () {
},

路由相關(guān):

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';
            }
        })
},

// 動態(tài)路由:路由的路徑是 /report/business-report/1234567 可以動態(tài)變化雀鹃,但是跳轉(zhuǎn)的文件只是一個vue文件栅螟,
{
    path: '/report/business-report/:id',
    meta: {
      title: '業(yè)務(wù)報表'
    },
    component: (resolve) => require(['@/views/report/business-report.vue'], resolve)
  }
// 在動態(tài)路由間切換時不會重新創(chuàng)建該vue文件(不會再走created 、mounted),想要知道路由切換需要監(jiān)聽路由變化:

watch: {
  '$route': function (newValue) {
      // 該方法只能監(jiān)聽動態(tài)路徑間的變化, 第一次進入該頁面不會走
   }
},

空頁面:

<template>
  <div class="main">

  </div>
</template>

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

<style scoped>
</style>

組件內(nèi)嵌套內(nèi)容的方法:

// 子組件:(核心是使用 slot 標(biāo)記子組件名稱)
<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添加內(nèi)容)
<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來標(biāo)識 happypack處理那里類文件
    id: 'happyBabel',
    // 如何處理  用法和loader 的配置一樣
    loaders: [{
      loader: 'babel-loader?cacheDirectory=true'
    }],
    // 共享進程池
    threadPool: happyThreadPool,
    // 允許 HappyPack 輸出日志
    verbose: true
  })
  ]

module: {
    rules: [{
      test: /\.js$/,
      // 把對.js 的文件處理交給id為happyBabel 的HappyPack 的實例執(zhí)行
      loader: 'happypack/loader?id=happyBabel',
      // 排除node_modules 目錄下的文件
      exclude: /node_modules/
    }]
  }

// 對應(yīng)庫可以去npm看下使用方法~

常用方法:

//過濾器
filters: {
},
//監(jiān)聽器
watch: {
    value: function (newValue) {

    },
}
//標(biāo)簽相關(guān)
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) // 假裝更改數(shù)組數(shù)據(jù) 強制更新dom

微信端vue項目跳轉(zhuǎn)HTML文件時返回會不刷新vue界面方法(包括路由),這樣會導(dǎo)致微信分享不受控制上岗,該問題只出現(xiàn)于 iOS (webview返回層緩存導(dǎo)致),解決方法:

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渲染時找不到對應(yīng)標(biāo)簽,可能dom渲染和echarts旋轉(zhuǎn)的先后出了問題.
解決方法:

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表已經(jīng)存在再重新init時會報這個警告
解決方法:

//在init方法前判斷是否dom中已經(jīng)存在,若存在則dispose()
var oldChart = echarts.getInstanceByDom(document.getElementById(chartId));
 if (oldChart) {
    oldChart.dispose();
}
this.currentChart = echarts.init(document.getElementById(chartId));
this.currentChart.setOption(chartOption);
option 相關(guān)解釋
chartOption = {
    //鼠標(biāo)滑過時展示的詳細數(shù)據(jù)相關(guān)設(shè)置
    tooltip: {
        trigger: 'axis',
        axisPointer: {
            type: 'cross',
            crossStyle: {
                color: '#999'
            }
        }
    },
    //表格兩邊的留白距離
    grid :[
       {
            left:"70px",
            right:'70px'
        }
    ],
    //表格頂部顯示的數(shù)據(jù)分類
    legend: {
        data:['蒸發(fā)量','降水量','平均溫度']
    },
    //X坐標(biāo)
    xAxis: [
        {
            type: 'category',
            data: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
            axisPointer: {
                type: 'shadow'
            },
            offset:10//X軸單位名稱上下編譯坐標(biāo)
        }
    ],
    //Y坐標(biāo)
    yAxis: [
        {
            type: 'value',
            name: '水量',
            min: 0, //最小值
            max: 250, //最大值
            interval: 50, //單位長度
            minInterval: 1,//坐標(biāo)軸最小間隔大小
            axisLabel: {
                //坐標(biāo)單位顯示格式化
                formatter: '{value} 萬'
            },
            splitLine: {
                //是否顯示橫線(平行于X軸對應(yīng)Y值得線)
                show: false
            },
        },
        {
            type: 'value',
            name: '溫度',
            min: 0,
            max: 25,
            interval: 5,
            axisLabel: {
                formatter: '{value} 個'
            },
            splitLine: {
                show: false
            },
        }
    ],
    //數(shù)據(jù)配置
    series: [
        {
            name:'蒸發(fā)量',
            type:'bar',
            // stack:'總量', //是否累加數(shù)據(jù)(數(shù)據(jù)堆疊蕴坪,同個類目軸上系列配置相同的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],
            //在圖上顯示數(shù)值
            label: {
                normal: {
                    show: true,
                    position: 'insideTop'
                }
            },
            //圖的顏色等風(fēng)格設(shè)置
            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軸時通過這個設(shè)置對應(yīng)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 // 頂點字體大小 不能設(shè)置 radio 否則不能生效
          },
          splitLine: {
            lineStyle: {
              color: '#00aaff' // 每一圈的邊界顏色
            }
          },
          axisLabel: {
            inside: true
          },
          axisLine: {
            lineStyle: {
              color: '#00aaff' // 半徑線顏色
            }
          },
          splitArea: {
            areaStyle: {
              // color: ['#00aaff', '#0099ff', '#00aaff', '#0099ff', '#00aaff'] // 每一圈的顏色
            }
          },
          indicator: [
              {text: '健康風(fēng)險', max: 100, color: '#099aed'}, // 選中顏色
              {text: '駕乘風(fēng)險', max: 100},
              {text: '固定資產(chǎn)', max: 100},
              {text: '財務(wù)風(fēng)險', max: 100},
              {text: '贍養(yǎng)撫養(yǎng)', 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', // 頂點數(shù)字顏色
                fontSize: 24,  // 頂點數(shù)字大小
                formatter: function (params) {
                  return params.value
                }
              }
            }
          }]
        }]
      }
雷達圖效果
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末背传,一起剝皮案震驚了整個濱河市呆瞻,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌续室,老刑警劉巖栋烤,帶你破解...
    沈念sama閱讀 216,692評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異挺狰,居然都是意外死亡明郭,警方通過查閱死者的電腦和手機买窟,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,482評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來薯定,“玉大人始绍,你說我怎么就攤上這事』爸叮” “怎么了亏推?”我有些...
    開封第一講書人閱讀 162,995評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長年堆。 經(jīng)常有香客問我吞杭,道長,這世上最難降的妖魔是什么变丧? 我笑而不...
    開封第一講書人閱讀 58,223評論 1 292
  • 正文 為了忘掉前任芽狗,我火速辦了婚禮,結(jié)果婚禮上痒蓬,老公的妹妹穿的比我還像新娘童擎。我一直安慰自己,他們只是感情好攻晒,可當(dāng)我...
    茶點故事閱讀 67,245評論 6 388
  • 文/花漫 我一把揭開白布顾复。 她就那樣靜靜地躺著,像睡著了一般鲁捏。 火紅的嫁衣襯著肌膚如雪芯砸。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,208評論 1 299
  • 那天碴萧,我揣著相機與錄音乙嘀,去河邊找鬼。 笑死破喻,一個胖子當(dāng)著我的面吹牛虎谢,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播曹质,決...
    沈念sama閱讀 40,091評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼婴噩,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了羽德?” 一聲冷哼從身側(cè)響起几莽,我...
    開封第一講書人閱讀 38,929評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎宅静,沒想到半個月后章蚣,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,346評論 1 311
  • 正文 獨居荒郊野嶺守林人離奇死亡姨夹,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,570評論 2 333
  • 正文 我和宋清朗相戀三年纤垂,在試婚紗的時候發(fā)現(xiàn)自己被綠了矾策。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,739評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡峭沦,死狀恐怖贾虽,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情吼鱼,我是刑警寧澤蓬豁,帶...
    沈念sama閱讀 35,437評論 5 344
  • 正文 年R本政府宣布,位于F島的核電站菇肃,受9級特大地震影響地粪,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜巷送,卻給世界環(huán)境...
    茶點故事閱讀 41,037評論 3 326
  • 文/蒙蒙 一驶忌、第九天 我趴在偏房一處隱蔽的房頂上張望矛辕。 院中可真熱鬧笑跛,春花似錦、人聲如沸聊品。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,677評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽翻屈。三九已至陈哑,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間伸眶,已是汗流浹背惊窖。 一陣腳步聲響...
    開封第一講書人閱讀 32,833評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留厘贼,地道東北人界酒。 一個月前我還...
    沈念sama閱讀 47,760評論 2 369
  • 正文 我出身青樓,卻偏偏與公主長得像嘴秸,于是被迫代替她去往敵國和親毁欣。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,647評論 2 354

推薦閱讀更多精彩內(nèi)容