已解决
vue 生命周期钩子函数 mounted()实例
来自网友在路上 192892提问 提问时间:2023-10-24 08:23:02阅读次数: 92
最佳答案 问答题库928位专家为你答疑解惑
在挂载后操作dom获取焦点。
<!DOCTYPE html>
<html lang="zh-CN"><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>示例-获取焦点</title><!-- 初始化样式 --><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reset.css@2.0.2/reset.min.css"><!-- 核心样式 --><style>html,body {height: 100%;}.search-container {position: absolute;top: 30%;left: 50%;transform: translate(-50%, -50%);text-align: center;}.search-container .search-box {display: flex;}.search-container img {margin-bottom: 30px;}.search-container .search-box input {width: 512px;height: 16px;padding: 12px 16px;font-size: 16px;margin: 0;vertical-align: top;outline: 0;box-shadow: none;border-radius: 10px 0 0 10px;border: 2px solid #c4c7ce;background: #fff;color: #222;overflow: hidden;box-sizing: content-box;-webkit-tap-highlight-color: transparent;}.search-container .search-box button {cursor: pointer;width: 112px;height: 44px;line-height: 41px;line-height: 42px;background-color: #ad2a27;border-radius: 0 10px 10px 0;font-size: 17px;box-shadow: none;font-weight: 400;border: 0;outline: 0;letter-spacing: normal;color: white;}body {background: no-repeat center /cover;background-color: #edf0f5;}</style>
</head><body>
<div class="container" id="app"><div class="search-container"><div class="search-box"><input type="text" v-model="words" id="inp"><button>搜索一下</button></div></div>
</div><script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>const app = new Vue({el: '#app',data: {words: ''},mounted() {document.querySelector('#inp').focus()},})
</script></body></html>
查看全文
99%的人还看了
相似问题
- 〖大前端 - 基础入门三大核心之JS篇㊲〗- DOM改变元素节点的css样式、HTML属性
- QT中样式表常见属性与颜色的设置与应用
- vue.js中使用三元运算符设置动态样式
- 修改el-radio-group样式,自定义单选组件
- el-popover和el-tooltip样式修改(普通的组件样式修改方法,对popover是不生效的)
- 禁止点击-样式及事件不可用
- css实现原生form表单label必填选项红色*样式,以及js控制必填校验
- duilib 实现登录界面 之 样式设计
- 用css实现原生form中radio单选框和input的hover已经focus的样式
- CSS---关于font文本属性设置样式总结
猜你感兴趣
版权申明
本文"vue 生命周期钩子函数 mounted()实例":http://eshow365.cn/6-23160-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!
- 上一篇: mac下配置环境-node以及nvm
- 下一篇: Spring中事务失效的几种场景及解决办法