面试编程题目错题

public class TestMain {
    
    
    public static void main(String[] args) {
    
    
  try {
    
    
           int a = args.length;
            System.out.println(a);  //打印结果a=0
            int b = 42 / a;
            int c[] = {
    
    1};
            int c1[]={
    
    1,2,3,4,5};
            System.out.println(c.length);
            System.out.println(c1.length);
            c[42] = 99;
            System.out.println("b=" + b);
        }catch (ArithmeticException e){
    
      //这个程序执行到这里就会报出异常
            System.out.println("除0异常:" + e);
        }catch (ArrayIndexOutOfBoundsException e){
    
    
            System.out.println("数组超越边界异常:" + e);
        }





    }
}

执行结果:

0
除0异常:java.lang.ArithmeticException: / by zero
finally 必须是执行的

try--------catch语句只要有一个抛出异常就会不执行下面的语句,也就是 catch只执行第一个,但是finally是必须执行的。

前端知识

1.vue-router是怎么传递参数的

this.KaTeX parse error: Unexpected character: '' at position 48: …outer传递参数分为两大类 ̲编程式的导航 router.p…router.push(“path”)
This.$router.push({name:’news’,’params’:{userId: 123})
声明式的导航
click to news page

2.beforeDestroyed里面一般进行什么操作

这个是vue的生命周期hooks函数,也就是在updated之后执行的,
beforeDestoryed和Destoryed可以用来进行销毁的操作。需要对页面进行刷新然后可以进行销毁。
在localstorage中存了数据,要求离开页面时需要把localstorage中相应的数据清空。于是我将清空storage的代码写在了beforeDestroy中。但在刷新页面时,storage并没有被清空。
beforeDestroy或destroyed时执行的代码,要额外考虑一下对页面刷新的处理。
1.没有加入缓存 离开当前的路由会直接调用。
2.加入了缓存,需要使用需要手动的调用。

3.vue中父组件如何获取子组件的属性和方法

父组件需要使用 ref属性:
<v-header ref=”header”> </v-header>

父组件函数中使用子组件的属性:

This.$refs.header.属性名
This.$refs.header.方法名

子组件调用父组件的属性和方法:

This.$parent.属性名
This.$parent.方法名

4.watch和computed的区别

watch是一个监听事件,里面的所有的事物的改变都可以触发watch里面的事件,可以用于计算等等实际操作。
通过method方法实现计算功能,不同的是计算属性是基于它们的依赖进行缓存的。计算属性只有在它的相关依赖发生改变时才会重新求值。所以computed比method更优化。
Computed:是一个计算函数,但是计算出来的是字符串上的形式,没有监听这个作用。
计算属性可以写为一个 Object,而非 Function
,只是 Function 形式是我们默认使用它的 get 方法,当写为 Object 时,我们还可以使用它的 set 方法
computed: {
fullName: {
get () {
return ${this.firstName} ${this.lastName};
},
set (val) {
const names = val.split(’ ');
this.firstName = names[0];
this.lastName = names[names.length - 1];
}
}
}

5.vue父组件和子组件生命周期的顺序

都是 new Vue()对象以后进行init()方法的操作,然后执行beforeCraeated 和created方法,再执行 beforeMounted和Mounted这个方法,然后执行beforedUpdated和updated这些方法,
注意一下:页面刷新才可以执行beforeDestroyed和Destoryed方法。

加载渲染过程:

父beforeCreate–>父created–>父beforeMount----->子BeforedCreate---->子created
----->子beforeMount---->子Mounted---->父mounted

子组件更新过程:

父beforeUpdate—>子beforeUpdate---->子updated---->父updated

父组件更新过程:

父beforeUpdated—>父updated

销毁过程:

父BeforeDestroy->子beforeDestroy---->子destroyed---->父Destroyed

猜你喜欢

转载自blog.csdn.net/houzhicongone/article/details/121619993