The solution record of Vue failing to obtain the element for the first time

The solution record of Vue failing to obtain the element for the first time

Preface

The solution to the problem of not being able to obtain elements for the first time in Vue is whether you often click the pop-up button for the first time to obtain the elements in the pop-up window. When you open the pop-up window to get the element, it is empty and you have to open it a second time to get it.

1. Get after updating DOM

this.$nextTick(callback)
methods: {
    play() {
        //Get the element console.log($('#video'));
        this.$nextTick(function() {
            //Get the element console.log($('#video'));
        });
    }
}

2. Get through timer

setTimeOut(fn, 0)
methods:{
    play() {
        //Get the element console.log($('#video'));
        setTimeOut(function(){
            //Get the element console.log($('#video'));
        }, 0);
    }
}

3. Get by triggering events

@opened
<el-dialog @opened="play"></el-dialog>
 
methods: {
    play() {
        //Get the element console.log($('#video'));
    }
}

Summarize

This is the end of this article about how to solve the problem that vue cannot get elements for the first time. For more relevant content about vue cannot get elements, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to get the dynamically generated element by vue class name
  • Description of the problem of using custom hooks to obtain DOM elements in Vue3
  • Vue implements dynamic assignment of id, and click event to obtain the id operation of the currently clicked element
  • Vue gets the data-v-xxx operation generated by the element
  • vue.js click event gets the operation of the current element object
  • How to get the specified element in Vue

<<:  How to build a multi-node Elastic stack cluster on RHEL8 /CentOS8

>>:  MySQL 8.0.13 installation and configuration method graphic tutorial under win10

Recommend

MySQL database connection exception summary (worth collecting)

I found a strange problem when deploying the proj...

How to force vertical screen on mobile pages

I recently wrote a mobile page at work, which was...

Vertical and horizontal splitting of MySQL tables

Vertical Split Vertical splitting refers to the s...

Detailed explanation of Vue3 life cycle functions and methods

1. Overview The so-called life cycle function is ...

Summary of Commonly Used MySQL Commands in Linux Operating System

Here are some common MySQL commands for you: -- S...

HTML Grammar Encyclopedia_HTML Language Grammar Encyclopedia (Must Read)

Volume Label, Property Name, Description 002 <...

Web Theory: Don't make me think Reading Notes

Chapter 1 <br />The most important principl...

Why Seconds_Behind_Master is still 0 when MySQL synchronization delay occurs

Table of contents Problem Description Principle A...

HTML 5.1 learning: 14 new features and application examples

Preface As we all know, HTML5 belongs to the Worl...

MySQL 8.0.20 Installation Tutorial with Pictures and Text (Windows 64-bit)

1: Download from mysql official website https://d...

Summary of javascript date tools

let Utils = { /** * Is it the year of death? * @r...

CentOS7 firewall and port related commands introduction

Table of contents 1. Check the current status of ...

Introduction to local components in Vue

In Vue, we can define (register) local components...

Open the Windows server port (take port 8080 as an example)

What is a Port? The ports we usually refer to are...

Vue3.0 adaptive operation of computers with different resolutions

First we need to install some dependencies npm i ...