new Vue({ el: '#app', data: function () { return { searchKey:'',//input的值 searchword:'',//搜索时传给子组件的值(可能input改变了未按搜索 所以分成两个) hotList:[], type:'全部', allEventInit:false, //判断是否需要重新加载数据 outpatientInit:false, hospitalizationInit:false, showBtn:true } }, computed: { }, mounted:function() { this.getHot(); this.searchKey =(GetRequest().search && decodeURIComponent(GetRequest().search)) || '' this.initData(this.searchKey); var vm=this; GlobalEventBus.$on('getSearchData',function(val){ if(val.data && val.data.length>0){ vm.showBtn =true } else{ vm.showBtn =false } }) }, methods: { getHot:function(){ var vm=this; bigDataOutApi.hot_words().then(function(res){ vm.hotList=res }).catch(function(err){ console.err(err) }) }, initData:function(keyword){ this.searchword=keyword this.allEventInit =false; this.outpatientInit =false; this.hospitalizationInit =false; var vm=this this.$nextTick(function () { switch (vm.type){ case '全部':vm.$refs.allEvent.initData();vm.allEventInit =true;break; case '门诊':vm.$refs.outpatient.initData();vm.outpatientInit =true;break; case '住院':vm.$refs.hospitalization.initData();vm.hospitalizationInit =true;break } }) }, setIndexPage:function(key){ //前往左边菜单页面 GlobalEventBus.$emit('setleftTabUrl', { key: key }); }, search:function(value){ if(!value){ toastr.error("请输入检索词再进行搜索"); return } this.searchKey=value this.initData(value); }, reseviceData:function(val){ debugger } }, watch: { type:function(value){ switch (value){ case '全部':if(!this.allEventInit){this.$refs.allEvent.initData();this.allEventInit =true};break; case '门诊':if(!this.outpatientInit){this.$refs.outpatient.initData();this.outpatientInit =true;}break; case '住院':if(!this.hospitalizationInit){this.$refs.hospitalization.initData();this.hospitalizationInit =true;}break } } } })