vue中让input框自动聚焦

  created(){
   this.changfouce();
  },
  methods: {
    //在vue生命周期的created()钩子函数进行的DOM操作要放在Vue.nextTick()的回调函数中,
    //因为created()钩子函数执行的时候DOM并未进行任何渲染,而此时进行DOM操作是徒劳的,所以此处一定要将DOM操作的JS代码放进Vue.nextTick()的回调函数中。
    changfouce(){
    this.$nextTick((x)=>{   //正确写法
       this.$refs.inputs.focus();
    })
     this.$refs.inputs.focus(); //错误写法
     
    },
原文地址:https://www.cnblogs.com/huanhuan55/p/10043816.html