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

Solve the problem that the time zone cannot be set in Linux environment

When changing the time zone under Linux, it is al...

PHP-HTMLhtml important knowledge points notes (must read)

1. Use frameset, frame and iframe to realize mult...

Docker removes abnormal container operations

This rookie encountered such a problem when he ju...

How to write the style of CSS3 Tianzi grid list

In many projects, it is necessary to implement th...

About the problem of offline installation of Docker package on CentOS 8.4

The virtual machine used is CentOS 8.4, which sim...

How does MySQL implement ACID transactions?

Preface Recently, during an interview, I was aske...

Use of nginx custom variables and built-in predefined variables

Overview Nginx can use variables to simplify conf...

Using react-virtualized to implement a long list of images with dynamic height

Table of contents Problems encountered during dev...

How to configure nginx to return text or json

Sometimes when requesting certain interfaces, you...

Practical method of deleting associated tables in MySQL

In the MySQL database, after tables are associate...

Detailed tutorial on compiling and installing MySQL 5.7.24 on CentOS7

Table of contents Install Dependencies Install bo...

Implementation of Docker to build private warehouse (registry and Harbor)

As more and more Docker images are used, there ne...

Detailed explanation of how Zabbix monitors the master-slave status of MySQL

After setting up the MySQL master-slave, you ofte...

How to represent various MOUSE shapes

<a href="http://" style="cursor...