Vue 中使用vue2-highcharts实现曲线数据展示的方法

1、要实现的效果如下图:

2、vue前端页面如下:

<template>
 <div>
  <div>
  <div>
    <img src="../assets/index/back.png" class="rank-head-back" @click="routerBack"/>
    <span >历史曲线</span>
  </div>
  </div>
  <div >
   <div >
    <span >{{$route.params.monitorName}}({{$route.params.meterId}})</span>
   </div>
  </div>
  <div >
   <div >
    <yesterdaypicker v-on:startPicked="startPicked" style="margin-left:10px;"></yesterdaypicker>
   </div>
    <div >
    <daypicker v-on:endPicked="endPicked" style="margin-left:10px;"></daypicker>
    </div>
  </div>
  <div >
   <div >
     <vchooser :selections="periodList" @on-change="onParamChange('versions', $event)"></vchooser>
   </div>
  </div>
  <div >
   <div class="charts" >
     <vue-highcharts :options="options" ref="lineCharts" ></vue-highcharts>
   </div>
  </div>
 </div>
</template>
<script>
 import vchooser from '../components/chooser.vue'
 import VueHighcharts from 'vue2-highcharts'
 import daypicker from '../components/daypicker.vue'
 import yesterdaypicker from '../components/yesterdaypicker.vue'
 export default {
 data() {
  return{
   startDay:'',
   endDay:'',
   setIntervalNum:0,
   itemStatus:0,
   itemTitle:'功率因数',
   itemType:this.$route.params.meterType,
   periodList:[
    {
    label: '功率因数',
    value: 0
    },
    {
    label: '电流',
    value: 1
    },{
    label: '电压',
    value: 2
    },{
    label: '有功功率',
    value: 3
    },{
    label: '无功功率',
    value: 4
    }/*,{
    label: '视在功率',
    value: 5
    }*/,{
    label: '有功电量',
    value: 6
    },
   ],
   ownerFreeData: [],
   options: {
   global: {
    useUTC: false
   },
   chart: {
    type: 'spline'
   },
   title: {
    text: '功率因素'
    //text: ' '
   },
   subtitle: {
    text: ''
   },
   xAxis: {
    type: 'category'
   },
   yAxis: {
    title: {
    text: '功率因素(%)'
    //text: ' '
    },
    labels: {
    formatter: function () {
     return this.value;
    }
    }
   },
   tooltip: {
    crosshairs: true,
    shared: true
   },
   credits: {
    enabled: false
   },
   plotOptions: {
    spline: {
    marker: {
     radius: 4,
     lineColor: '#666666',
     lineWidth: 1
    }
    }
   },
   series: []
   }
  }
 },
  methods: {
  startPicked(year, month, date) {
   //this.ownerFreeData = []
   if(this.$refs.lineCharts != null){
    this.$refs.lineCharts.removeSeries();
   }
   var monthStr = '';
   var dayStr = '';
   if(month < 10){
    monthStr = `0${month}`;
   }else{
    monthStr = `${month}`;
   }
   if(date < 10){
    dayStr = `0${date}`;
   }else{
    dayStr = `${date}`;
   }
   this.startDay = `${year}-` + monthStr + '-' + dayStr;
   if(this.$refs.lineCharts != null){
    this.getList();
   }
  },
  endPicked(year, month, date) {
   //this.ownerFreeData = []
   if(this.$refs.lineCharts != null){
    this.$refs.lineCharts.removeSeries();
   }
   var monthStr = '';
   var dayStr = '';
   if(month < 10){
    monthStr = `0${month}`;
   }else{
    monthStr = `${month}`;
   }
   if(date < 10){
    dayStr = `0${date}`;
   }else{
    dayStr = `${date}`;
   }
   this.endDay = `${year}-` + monthStr + '-' + dayStr;
   if(this.$refs.lineCharts != null){
    this.getList();
   }
  },
  onParamChange (attr, val) {
   this.itemStatus = val.value;
   if(this.$refs.lineCharts != null){
    this.$refs.lineCharts.removeSeries();
   }
   if(this.$refs.lineCharts != null){
    this.getList();
   }
  },
  routerBack(){
   //let lineCharts = this.$refs.lineCharts;
   //lineCharts.getChart().destroy();
   //this.$router.go(-1);
   var mid = this.$route.params.id;
   var mname = this.$route.params.name;
   var mpname = this.$route.params.pname;
   this.$router.push({name: 'timeSortPoint', params: {id: mid,name:mname,pname:mpname}});
  },
  setType(){
   var title = '';
   let lineCharts = this.$refs.lineCharts;
   if(this.itemStatus == 0){
    title = '功率因素';
    lineCharts.getChart().title.update({ text: '功率因素' });
    lineCharts.getChart().yAxis[0].setTitle({text:'功率因素(%)'});
    if(this.itemType == 0){
     lineCharts.addSeries({name: this.startDay + ' 功率因素',data: []});
     lineCharts.addSeries({name: this.endDay + ' 功率因素',data: []});
    }else if(this.itemType == 1){
     lineCharts.addSeries({name: this.startDay + ' 总功率因素',data: []});
     lineCharts.addSeries({name: this.startDay + ' A相功率因素',data: []});
     lineCharts.addSeries({name: this.startDay + ' B相功率因素',data: []});
     lineCharts.addSeries({name: this.startDay + ' C相功率因素',data: []});
     lineCharts.addSeries({name: this.endDay + ' 总功率因素',data: []});
     lineCharts.addSeries({name: this.endDay + ' A相功率因素',data: []});
     lineCharts.addSeries({name: this.endDay + ' B相功率因素',data: []});
     lineCharts.addSeries({name: this.endDay + ' C相功率因素',data: []});
    }
   }else if(this.itemStatus == 1){
    title = '电流';
    lineCharts.getChart().title.update({ text: '电流' });
    lineCharts.getChart().yAxis[0].setTitle({text:'电流(A)'});
    if(this.itemType == 0){
     lineCharts.addSeries({name: this.startDay + ' 电流',data: []});
     lineCharts.addSeries({name: this.endDay + '电流',data: []});
    }else if(this.itemType == 1){
     lineCharts.addSeries({name: this.startDay + ' Ia 相电流',data: []});
     lineCharts.addSeries({name: this.startDay + ' Ib 相电流',data: []});
     lineCharts.addSeries({name: this.startDay + ' Ic 相电流',data: []});
     lineCharts.addSeries({name: this.startDay + ' 零序电流',data: []});
     lineCharts.addSeries({name: this.endDay + ' Ia 相电流',data: []});
     lineCharts.addSeries({name: this.endDay + ' Ib 相电流',data: []});
     lineCharts.addSeries({name: this.endDay + ' Ic 相电流',data: []});
     lineCharts.addSeries({name: this.endDay + ' 零序电流',data: []});
    }
   }else if(this.itemStatus == 2){
    title = '电压';
    lineCharts.getChart().title.update({ text: '电压' });
    lineCharts.getChart().yAxis[0].setTitle({text:'电压(V)'});
    if(this.itemType == 0){
     lineCharts.addSeries({name: this.startDay + ' 电压',data: []});
     lineCharts.addSeries({name: this.endDay + ' 电压',data: []});
    }else if(this.itemType == 1){
     lineCharts.addSeries({name: this.startDay + ' A相电压',data: []});
     lineCharts.addSeries({name: this.startDay + ' B相电压',data: []});
     lineCharts.addSeries({name: this.startDay + ' C相电压',data: []});
     lineCharts.addSeries({name: this.endDay + ' A相电压',data: []});
     lineCharts.addSeries({name: this.endDay + ' B相电压',data: []});
     lineCharts.addSeries({name: this.endDay + ' C相电压',data: []});
    }
   }else if(this.itemStatus == 3){
    title = '有功功率';
    lineCharts.getChart().title.update({ text: '有功功率' });
    lineCharts.getChart().yAxis[0].setTitle({text:'有功功率(KVA)'});
    if(this.itemType == 0){
     lineCharts.addSeries({name: this.startDay + ' 有功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' 有功功率',data: []});
    }else if(this.itemType == 1){
     lineCharts.addSeries({name: this.startDay + ' 总有功功率',data: []});
     lineCharts.addSeries({name: this.startDay + ' A相有功功率',data: []});
     lineCharts.addSeries({name: this.startDay + ' B相有功功率',data: []});
     lineCharts.addSeries({name: this.startDay + ' C相有功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' 总有功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' A相有功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' B相有功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' C相有功功率',data: []});
    }
   }else if(this.itemStatus == 4){
    title = '无功功率';
    lineCharts.getChart().title.update({ text: '无功功率' });
    lineCharts.getChart().yAxis[0].setTitle({text:'有功功率(KVA)'});
    if(this.itemType == 0){
     lineCharts.addSeries({name: this.startDay + ' 无功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' 无功功率',data: []});
    }else if(this.itemType == 1){
     lineCharts.addSeries({name: this.startDay + ' 总无功功率',data: []});
     lineCharts.addSeries({name: this.startDay + ' A相无功功率',data: []});
     lineCharts.addSeries({name: this.startDay + ' B相无功功率',data: []});
     lineCharts.addSeries({name: this.startDay + ' C相无功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' 总无功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' A相无功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' B相无功功率',data: []});
     lineCharts.addSeries({name: this.endDay + ' C相无功功率',data: []});
    }
   }else if(this.itemStatus == 5){
   }else if(this.itemStatus == 6){
    title = '总有功电量';
    lineCharts.getChart().title.update({ text: '总有功电量' });
    lineCharts.getChart().yAxis[0].setTitle({text:'总有功电量(KWH)'});
    lineCharts.addSeries({name: this.startDay + ' 总有功电量',data: []});
    lineCharts.addSeries({name: this.endDay + '总有功电量',data: []});
   }
  },
  getList(){
   var title = '';
   let lineCharts = this.$refs.lineCharts;
   var meterId = this.$route.params.meterId;
   this.setType();
   this.$http.post(this.URLINFO + '/mobile/electricity/getElectricityApp.do',{meterId:meterId,startDay:this.startDay,endDay:this.endDay})
   .then(function (res) {
    for(var i = 0;i < res.data.ls1.length; i++) {
     if(this.itemStatus == 0){
      if(this.itemType == 0){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].totalnum],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].totalnum],false,false);
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].numa],false,false);
       lineCharts.getChart().series[2].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].numb],false,false);
       lineCharts.getChart().series[3].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].numc],false,false);
      }
     }else if(this.itemStatus == 1){
      if(this.itemType == 0){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ia[i].ia],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].ia],false,false);
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].ib],false,false);
       lineCharts.getChart().series[2].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].ic],false,false);
       lineCharts.getChart().series[3].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].zeroi],false,false);
      }
     }else if(this.itemStatus == 2){
      if(this.itemType == 0){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ia[i].ua],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].ua],false,false);
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].ua],false,false);
       lineCharts.getChart().series[2].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].uc],false,false);
      }
     }else if(this.itemStatus == 3){
      if(this.itemType == 0){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ia[i].totalp],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].pa],false,false);
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].pb],false,false);
       lineCharts.getChart().series[2].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].pc],false,false);
      }
     }else if(this.itemStatus == 4){
      if(this.itemType == 0){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ia[i].reactivep],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ia[i].reactivep],false,false);
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].reactivepa],false,false);
       lineCharts.getChart().series[2].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].reactivepb],false,false);
       lineCharts.getChart().series[3].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ls1[i].reactivepc],false,false);
      }
     }else if(this.itemStatus == 6){
      lineCharts.getChart().series[0].addPoint([getTimeStr(res.data.ls1[i].transtime),res.data.ia[i].readNum],false,false);
     }
    }
    for(var i = 0;i < res.data.ls2.length; i++) {
     if(this.itemStatus == 0){
      if(this.itemType == 0){
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].totalnum],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[4].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].totalnum],false,false);
       lineCharts.getChart().series[5].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].numa],false,false);
       lineCharts.getChart().series[6].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].numb],false,false);
       lineCharts.getChart().series[7].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].numc],false,false);
      }
     }else if(this.itemStatus == 1){
      if(this.itemType == 0){
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].ia],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[4].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].ia],false,false);
       lineCharts.getChart().series[5].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].ib],false,false);
       lineCharts.getChart().series[6].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].ic],false,false);
       lineCharts.getChart().series[7].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].zeroi],false,false);
      }
     }else if(this.itemStatus == 2){
      if(this.itemType == 0){
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].ua],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[3].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].ua],false,false);
       lineCharts.getChart().series[4].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].ub],false,false);
       lineCharts.getChart().series[5].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].uc],false,false);
      }
     }else if(this.itemStatus == 3){
      if(this.itemType == 0){
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].totalp],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[4].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].totalp],false,false);
       lineCharts.getChart().series[5].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].pa],false,false);
       lineCharts.getChart().series[6].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].pb],false,false);
       lineCharts.getChart().series[7].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].pc],false,false);
      }
     }else if(this.itemStatus == 4){
      if(this.itemType == 0){
       lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].reactivep],false,false);
      }else if(this.itemType == 1){
       lineCharts.getChart().series[4].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].reactivep],false,false);
       lineCharts.getChart().series[5].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].reactivepa],false,false);
       lineCharts.getChart().series[6].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].reactivepb],false,false);
       lineCharts.getChart().series[7].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].reactivepc],false,false);
      }
     }else if(this.itemStatus == 6){
      lineCharts.getChart().series[1].addPoint([getTimeStr(res.data.ls2[i].transtime),res.data.ls2[i].readNum],false,false);
     }
    }
    lineCharts.getChart().redraw();
   })
   .catch(function (error) {
    console.log(error)
    this.$toast('查询业主电费异常');
   });
  }
  },
  components: {
   vchooser,
  VueHighcharts,
  daypicker,
  yesterdaypicker
  },
 mounted () {
  this.getList()
 }
 }
 function getCurrentTime(){
 var date = new Date();
 var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
 var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
 var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
 return hour + ':' + minute + ':' + second;
 }
 function getTime(nS){
  return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17)
 }
 function formatDate(now) {
  var year=now.getYear();
  var month=now.getMonth()+1;
  var date=now.getDate();
  var hour=now.getHours();
  var minute=now.getMinutes();
  var second=now.getSeconds();
  //return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second;
  return hour+":"+minute+":"+second;
 }
 function getTimeStr(ns){
  var d=new Date(ns);
  return formatDate(d);
 }
</script>
<style>
*{margin:0;padding:0; list-style:none }
h1,h2,h3,h4,h5,h6{font-size:16px; font-weight:normal;}
.rank-head{
  width: 100%;
  height: 40px;
  position:fixed;
  background: -webkit-linear-gradient(top,rgba(0,0,0,.6),rgba(0,0,0,0));
  z-index: 999;
  color: #fff;
  font-size: 16px;
  text-align: center;
  line-height: 40px;
}
.container{
  width: 100%;
  overflow: hidden
}
.rank-head-back{
  display: block;
  float: left;
  width: 40px;
  height: 40px;
  background: url("../assets/index/back.png") no-repeat center center;
  background-size: 100% 100%;
}
</style>

以上这篇Vue 中使用vue2-highcharts实现曲线数据展示的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

您可能感兴趣的文章:

  • 在Vue中使用highCharts绘制3d饼图的方法
  • 动态更新highcharts数据的实现方法
(0)

相关推荐

  • 在Vue中使用highCharts绘制3d饼图的方法

    highcharts是国外知名基于javascript的图表库.由于中文官网的vue中使用highcharts配置繁琐并且需要引入jquery作为依赖,所以弃用. 接下来,给各位伙伴简要的讲叙下highcharts在vue中的使用和配置方法. 首先使用 npm在你的项目中安装vue-highcharts npm install vue-highcharts --save 由于vue-highcharts依赖于highcharts,我们还需要安装后者 npm install highcharts

  • 动态更新highcharts数据的实现方法

    动态更新highcharts数据的实现方法 <!doctype html> <html> <head> <script type="text/javascript" src="http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js"></script> <script type="text/javascript" src="htt

  • Vue 中使用vue2-highcharts实现曲线数据展示的方法

    1.要实现的效果如下图: 2.vue前端页面如下: <template> <div> <div> <div> <img src="../assets/index/back.png" class="rank-head-back" @click="routerBack"/> <span >历史曲线</span> </div> </div> &l

  • Vue中的v-for指令不起效果的解决方法

    我的代码之前类似下面的结构 <div id="example-1" v-for="item in items"> <ul> <li> {{ item.message }} </li> </ul> </div> 结果发现不好用,数据读入了但是没有显示 于是我后来看官网的例子才明白,原来是id和v-for不在一个层级上,官网的例子如下,我按照不在一个层级上改,果然好用了 <ul id=&quo

  • vue 通过 Prop 向子组件传递数据的实现方法

    这是一个通过 Prop 向子组件传递数据的小例子. 代码: <!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta charset="UTF-8"> <title></title> <style> *{ margin: 0; padding: 0; text-decoration: none; } </style> &

  • vue中data改变后让视图同步更新的方法

    前言 不久前天看到一个比较有趣的问题,vue中data改变后,如何让视图同步更新,搜索了一下,并没有发现解决问题的方法,只能从源码去找解决方法了. 原因 我们都知道,在vue中改变数据后,视图并不是同步更新的. 在vue实例初始化后,会将data设置为响应式对象,当我们执行this.xxx = 1时,会触发这个响应式对象的setter.在setter中,会触发更新,通知所有订阅了xxx的订阅者.但是这个触发更新并不是同步的,它会将所有的watcher都添加到一个队列,并在nextTick之后去更

  • vue中自定义指令(directive)的基本使用方法

    目录 前言 正文 1.全局注册 2.局部注册 3.钩子函数及参数设置 4.灵活用法 (1)动态指令参数 (2)函数简写方式 (3)对象字面量方式 5.使用场景 写在最后 前言 在vue项目中我们经常使用到 v-show ,v-if,v-for等内置的指令,除此之外vue还提供了非常方便的自定义指令,供我们对普通的dom元素进行底层的操作.使我们的日常开发变得更加方便快捷.本文就来总结一下自定义指令的使用方法及常用的场景. 正文 1.全局注册 这里全局注册一个指令,用于使用该指令的元素加一个红色边

  • Vue中接收二进制文件流实现pdf预览的方法

    后台Controller @RequestMapping("/getPDFStream") @ResponseBody public void getPDFStream(HttpServletRequest request,HttpServletResponse response) { try { request.setCharacterEncoding("utf-8"); } catch (UnsupportedEncodingException e) { log

  • vue中Axios添加拦截器刷新token的实现方法

    目录 1. Axios基本用法: 2. Axios基本封装用法: 3. 添加拦截器的用法 4. 注意事项: Axios是一款网络前端请求框架,基本用法如下: 1. Axios基本用法: const response = await Axios.create({ baseURL: "https://test.api.com", headers: { 'Content-Type': 'application/json', }, }).post<RequestResponse>(

  • Vue父组件和子组件之间数据传递和方法调用

    vue组件在通信中,无论是子组件向父组件传值还是父组件向子组件传值,他们都有一个共同点就是有中间介质,子向父的介质是自定义事件,父向子的介质是props中的属性. 父组件向子组件传值(子组件主动获取父组件的数据和方法) 父组件import引用子组件 使用子组件时在子组件上添加一个v-bind属性,并绑定上数据 在子组件中创建 props ,在props 中创建相同的属性名,用来接收数据 把接收到的数据在子组件中使用 子组件向父组件传值(父组件主动获取子组件的数据和方法) 子组件中需要发出该自定义

  • Android编程实现在Activity中操作刷新另外一个Activity数据列表的方法

    本文实例讲述了Android编程实现在Activity中操作刷新另外一个Activity数据列表的方法.分享给大家供大家参考,具体如下: 做Android项目中遇到这样一个问题:有两个acticity,一个显示好友列表,另外一个显示会话列表,现在问题是在会话界面增加一个添加好友功能,添加好友后要求实时的刷新好友列表. 想了想,找了两种方式 方法一:通过声明要刷新的activity(FriendActivity)为静态变量,然后在一个activity(SessionActivity)中直接调用刷新

  • vue自定义键盘信息、监听数据变化的方法示例【基于vm.$watch】

    本文实例讲述了vue自定义键盘信息.监听数据变化的方法.分享给大家供大家参考,具体如下: @keydown.up @keydown.enter @keydown.a/b/c.... 自定义键盘信息: Vue.directive('on').keyCodes.ctrl=17; Vue.directive('on').keyCodes.myenter=13; @keydown.a/b/c.... <input type="text" @keydown.c="show&quo

随机推荐