vue面试题

 1  methods: {
 2     //搜索按钮的回调
 3     goSearch() {
 4       //路由的跳转,采用的是编程式导航.
 5       //路由传递参数
 6 
 7       //第一种传递query参数
 8       // this.$router.push({path:'/search',query:{keyword:this.keyword}});
 9 
10       //第二种传递params参数 [一定要注意,面试的时候经常问]
11       // this.$router.push({name:'search',params:{keyword:this.keyword}})
12 
13       //第三种传递query+params
14       // this.$router.push({
15       //   name: "search",
16       //   params: { keyword: this.keyword },
17       //   query: { keyword: "ABC" },
18       // });
19 
20       //验证Vue-Router引入Promise技术,最笨的方法,给push传递第二个、第三个参数【回调函数】
21       //下面这种写法:治标不治本!!!!
22       // let result = this.$router.push({name: "search",params: { keyword: this.keyword|| undefined}},()=>{},()=>{});
23 
24       //问题1:push方法,里面this是谁? vueRouter类的实例
25       // this.$router.push({name:'search',params:{keyword:this.keyword}});
26       //问题2:push方法里面的this是谁?windows
27       // let result = this.$router.push;
28       // result({name:'search',params:{keyword:this.keyword}})
29 
30       //点击搜索按钮之前,如果路径当中有query参数,需要携带给search
31 
32       let locations = {
33         name: "search",
34         params: { keyword: this.keyword || undefined },
35       };
36       //确定路径当中有query参数
37       if (this.$route.query.categoryName) {
38         locations.query = this.$route.query;
39       }
40 
41       this.$router.push(locations);
42     },
43     //退出登录的按钮的回调
44     logout(){
45        //派遣action退出登录
46        this.$store.dispatch('logout');
47     }
48   },
49   mounted() {
50     //清除关键字
51     this.$bus.$on("clearKeyword", () => {
52       console.log(123);
53       this.keyword = "";
54     });
55   },
56 };

 防抖与节流   使用lodash

1 8)函数防抖与节流*******面试题
2 
3 正常:事件触发非常频繁,而且每一次的触发,回调函数都要去执行(如果时间很短,而回调函数内部有计算,那么很可能出现浏览器卡顿)
4 
5 防抖:前面的所有的触发都被取消,最后一次执行在规定的时间之后才会触发,也就是说如果连续快速的触发,只会执行最后一次
6 
7 节流:在规定的间隔时间范围内不会重复触发回调,只有大于这个时间间隔才会触发回调,把频繁触发变为少量触发
8 
9 今晚需要把防抖与节流的原理,通过JS实现【闭包 + 延迟器】

节流
changIndex:_.throttle(function (index){
this.currentIndex=index
},50),

 

posted @ 2022-10-24 08:56  小闫的姑娘  阅读(19)  评论(0编辑  收藏  举报