1、创建全局过滤器

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
//main.js 中

Object.keys(allFilter).forEach(key => {
  Vue.filter(key,allFilter[key])
})

//base_filter中

//获取yyyy-mm-dd类型时间
let getDate = value => {
	return formateDate("yyyy-MM-dd",value);
}

export { 
    getDate,
 } 

函数中调用filter方法

1
 this.$options.filters[filter](...args)

2、路由常见操作

1、获取路由参数

1
2
this.$route.query.perams;

2、路由跳转

1
2
_this.$router.push({"path":path,"query":querys});

3.watch

1、监听路由变化

1
2
3
4
5
6
7
8
watch: {
    $route: {
      handler: function(route) {
        this.redirect = route.query && route.query.redirect;
      },
      immediate: true
    }
  }

2、监听对象/数组

1
2
3
4
5
6
7
8
    example2:{
      //注意:当观察的数据为对象或数组时,curVal和oldVal是相等的,因为这两个形参指向的是同一个数据对象
      handler(curVal,oldVal){
        conosle.log(curVal,oldVal)
      },
      deep:true
  }

3、普通监听

1
2
3
4
5
6
7
8
example0(curVal,oldVal){
   console.log(curVal,oldVal);
},

//也可为函数名

example0:函数名

4、组件传参

1、父组件调用子组件方法

1
2
this.$.refs.child.childFn()