search

Home  >  Q&A  >  body text

vue.js - A project developed by vue. I want to automatically focus the input when the page is opened. I use the official custom instructions, but the test on the real iOS machine is invalid.

Vue.directive('focus', {
  // 当绑定元素插入到 DOM 中。
  inserted: function (el) {
    // 聚焦元素
    el.focus()
  }
})
<input type="text" v-focus>
某草草某草草2687 days ago2797

reply all(3)I'll reply

  • 为情所困

    为情所困2017-07-06 10:38:42

    You can use autofocus="autofocus"

    reply
    0
  • 我想大声告诉你

    我想大声告诉你2017-07-06 10:38:42

    According to this page, autofocus is not supported in iphone/ipad for usability reasons.

    According to this article autofocus or el.focus() Due to user experience issues, Apple does not allow it to be used on iPhone/iPad. Because focus may cause the page to zoom, open the page, and suddenly zoom, the experience is too bad, and the Big Apple can't stand it.

    reply
    0
  • 三叔

    三叔2017-07-06 10:38:42

    Do it manually...
    mounted() {
    xxx.focus()
    }

    reply
    0
  • Cancelreply