八才斗
2018-05-28 16:15
输入框变成空之后,我还想鼠标 focus,应该怎么做?
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="https://cdn.jsdelivr.net/npm/vue@2.5.17/dist/vue.js"></script> </head> <body> <div id="root"> <div> <input v-model="inputValue" :autofocus="is_focus"/> <button @click="handleClick">提交</button> </div> <ul> <li v-for="item of list" :key="item">{{item}}</li> </ul> </div> <script> new Vue({ el: '#root', data: { list: ['a', 'b', 'c'], inputValue: '', is_focus: '', }, methods: { handleClick: function () { this.list.push(this.inputValue); this.inputValue = ''; this.is_focus = true; } } }) </script> </body> </html>
应该是可以用到html5的新特性 autofocus 然后也通过双向绑定的方法在执行清空value值的同时使autofocus为true
vue2.5入门
146825 学习 · 657 问题
相似问题