美文网首页
2021 web面试题常见vue之一 $nextTick 05

2021 web面试题常见vue之一 $nextTick 05

作者: litielongxx | 来源:发表于2021-08-23 14:29 被阅读0次

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>
<body>
<div id="app">
<h3>点击button显示input框后自动聚焦</h3>
<button @click="show">点击显示</button>
<input ref="xx" type="text" v-show="flag">
</div>
<script>
var app=new Vue({
el:'#app',
data() {
return {
// 函数返回因为每次都是新作用域,不会造成引用组件时影响一个个新组件
//应该也听过每一个页面都是,router-view下的新组件说法
flag:false
}
},
methods: {
show() {
this.flag=true
// 错误示范
// this.refs.xx.focus() // 正确示范 this.nextTick(()=>{
// 不知道ref就打印看看
this.$refs.xx.focus()
})
}
},
})
</script>
</body>
</html>

相关文章

网友评论

      本文标题:2021 web面试题常见vue之一 $nextTick 05

      本文链接:https://www.haomeiwen.com/subject/hptgbltx.html