2021年4月24日星期六

vue popup input get focus automatically

i am using vue 2.x

i have a html looks like:

<body>      <div id="myDiv">          <input type="text" v-model="input" @click="showPopup"/>          <div id="popupDiv" ....>              <textarea v-model="textarea" ref="popup"></textarea>          </div>      </div>      <script>          myVM = new Vue({              name: 'myVM',              el: 'myDiv',              data() {                  return {                      input: '',                      textarea: ''                  }              },              methods: {                                showPopup() {                                        show popup dialog                  }              }          })      </script>  </body>  

when user click this input, the popup dialog will be shown.

now i want the textarea of popup dialog get focus automatically when popup dialog shown, so i tried to use this.$refs.popup.focus() in showPopup(), but it doesn't works.

https://stackoverflow.com/questions/67248847/vue-popup-input-get-focus-automatically April 25, 2021 at 09:04AM

没有评论:

发表评论