Vue.js知识点汇集

1.页面传值:

源页面:

 showScreen(){
  let routeData = this.$router.resolve({path:'/company-show',query:{companyId:this.companyId,year:this.year}});
  window.open(routeData.href, '_blank');
 }

目标页面:

 mounted() {
      this.companyId = this.$route.query.companyId;
      this.year = this.$route.query.year;
    },

2.定时器:

 mounted() {
     this.timer=setInterval(this.loadIndustryOrderChart,30000);
    },
beforeDestroy(){
clearInterval(this.timer);
}
 

3.引入echarts

const echarts = require('echarts')

 4.同时循环多个数据源(多个数据源循环同步):

<li v-for="(item,index) in arr">{{item.name}}{{age[index]}}</li>

 5.store:

store用于临时存储全局变量,方便一个地方存储,而另一个地方获取,一般用于页面之间传值等等。

定义一个store

const process = {
    state: {
        processId: null
    },
    mutations: {
        SET_PROCESS_ID: (state, id) => {
            state.processId = id;
        }
    }
};
export default process;

然后在写入值的地方:

this.$store.commit("SET_PROCESS_ID", m);

在引用的地方写:

this.$store.state.process.processId

6.axios发出get请求时,遇到数组字段,会生成****[]=,这种形式,出现400解析错误,解决方法:

export function getValue(parameter) {
    return axios({
        url: api.getValue,
        method: 'get',
        params: parameter,
        paramsSerializer: function(params) {
            return qs.stringify(params, {arrayFormat: 'repeat'})
        }
    })
}

 记得引入:import qs from 'qs'

文章出处:www.cnblogs.com/jizhong

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。否则保留追究法律责任的权利。

原文地址:https://www.cnblogs.com/jizhong/p/13114556.html