Home > Web Front-end > JS Tutorial > body text

Detailed explanation of vue project js import loading sequence

韦小宝
Release: 2018-03-14 18:26:56
Original
4529 people have browsed it

. After entering the vue project to study, errors often occur about the improper loading order after js import. This article mainly shares with you the detailed explanation of the js import and loading order in the vue project. I hope it can help everyone.

In the imported js:

 var block = document.getElementById("block");    
 // 绑定touchstart事件
block.addEventListener("touchstart", function(e) {});
Copy after login

2. Since the interface is parsed and loaded from top to bottom, if the js is not loaded after all the interface is loaded, An error will be reported, as shown below:

Detailed explanation of vue project js import loading sequence

3. At this time, you need to use the mounted method in the vue project to expose the js method

a.vue

import {touchAction} from '../../static/js/touchAction.js';
Copy after login
 mounted(){   touchAction();
  },
Copy after login
<img src="../../static/pic/btn-control.png" alt="" class="control-derection" id="block">
Copy after login

b.js

export let touchAction = function () {
    console.log("clientWidth:"+document.body.clientWidth);    var block = document.getElementById("block");
    block.addEventListener("touchstart", function(e) {})
}
Copy after login

Related recommendations:

Vue loading order example discussion

Detailed explanation of the loading order and execution principle of high-performance javascript

The loading order and execution of html, css and js files

The above is the detailed content of Detailed explanation of vue project js import loading sequence. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template