vue 项目常见功能(搜索 时间戳转换 过滤器)

//搜索功能
<button @click="search">搜索

   //子组件
methods:{
search(){
this.$router.push({ path:'/路由',query: { kw: this.keywords}}); 
}
}

     //父组件 

  computed: {   //计算属性
keywords: function () {
return this.$route.query.kw;   //接受数据
}
},
watch:{    //监听函数
keywords:function(){
this.getShopList();  //刷新列表数据
}
}
 //过滤器
   main.js中
 // 图片过滤器
Vue.filter('link', function (value) {
return 'http://192.168.1.8:000' + value
// 返回处理后的值
})
//时间戳过滤器
Vue.filter('time', function (value, formatString) {
formatString = formatString || 'YYYY-MM-DD HH:mm:ss';
return moment.unix(value).format(formatString); // 这是时间戳转时间
});