• vue 生命周期钩子函数 mounted()实例


    在挂载后操作dom获取焦点。

    1. html>
    2. <html lang="zh-CN">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
    6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    7. <title>示例-获取焦点title>
    8. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reset.css@2.0.2/reset.min.css">
    9. <style>
    10. html,
    11. body {
    12. height: 100%;
    13. }
    14. .search-container {
    15. position: absolute;
    16. top: 30%;
    17. left: 50%;
    18. transform: translate(-50%, -50%);
    19. text-align: center;
    20. }
    21. .search-container .search-box {
    22. display: flex;
    23. }
    24. .search-container img {
    25. margin-bottom: 30px;
    26. }
    27. .search-container .search-box input {
    28. width: 512px;
    29. height: 16px;
    30. padding: 12px 16px;
    31. font-size: 16px;
    32. margin: 0;
    33. vertical-align: top;
    34. outline: 0;
    35. box-shadow: none;
    36. border-radius: 10px 0 0 10px;
    37. border: 2px solid #c4c7ce;
    38. background: #fff;
    39. color: #222;
    40. overflow: hidden;
    41. box-sizing: content-box;
    42. -webkit-tap-highlight-color: transparent;
    43. }
    44. .search-container .search-box button {
    45. cursor: pointer;
    46. width: 112px;
    47. height: 44px;
    48. line-height: 41px;
    49. line-height: 42px;
    50. background-color: #ad2a27;
    51. border-radius: 0 10px 10px 0;
    52. font-size: 17px;
    53. box-shadow: none;
    54. font-weight: 400;
    55. border: 0;
    56. outline: 0;
    57. letter-spacing: normal;
    58. color: white;
    59. }
    60. body {
    61. background: no-repeat center /cover;
    62. background-color: #edf0f5;
    63. }
    64. style>
    65. head>
    66. <body>
    67. <div class="container" id="app">
    68. <div class="search-container">
    69. <div class="search-box">
    70. <input type="text" v-model="words" id="inp">
    71. <button>搜索一下button>
    72. div>
    73. div>
    74. div>
    75. <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js">script>
    76. <script>
    77. const app = new Vue({
    78. el: '#app',
    79. data: {
    80. words: ''
    81. },
    82. mounted() {
    83. document.querySelector('#inp').focus()
    84. },
    85. })
    86. script>
    87. body>
    88. html>

  • 相关阅读:
    38Java Math类
    全志A40i android7.1 移植wifi驱动的一般流程
    AcreleMS-SW污水处理厂电力监控系统——智慧水务
    【nginx】详细配置
    【编程题】【Scratch三级】2021.06 绘制图形
    靶机练习: Vikings
    一本通1084;幂的末尾
    16、学习MySQL 正则表达式
    三、支付宝支付对接 - 申请、配置、签约、获取RSkey(1)
    Redis 解决事务冲突之乐观锁和悲观锁
  • 原文地址:https://blog.csdn.net/qq_64628470/article/details/133996583