How to ensure that the JS introduced by the script tag has been loaded in VUE?

clipboard.png
vuescript JS,

mounted js

clipboard.png

script js ,,

clipboard.png
so, to fix this BUG, you must make sure that the external js is loaded, but I don"t know how to make sure that the JS is loaded. May I ask the gods how to do this?


listen for onload events

var scriptEle = document.createElement('script')
scriptEle.onload = function() {
    console.log('')
}
document.body.appendChild(scriptEle)

Thank you for the invitation!

< hr >

it is recommended to introduce echarts into main.js and register on the prototype of vue !
1, npm install echarts-- save
2, in main.js :

import echarts from 'echarts';
Vue.prototype.$echarts = echarts;

3. You can now get $echarts

registered to the prototype in the global vue . < hr >

A suggestion: generally echarts needs to be initialized before use, so initialization is best done in vue :

mounted() {
    //
    //documentidref
    //ref
    this.obj_echarts = this.$echarts.init(document.getElementById('xxx'));
},
data(){
    return {
        obj_echarts: null
    }
}
< hr >
I hope my answer will be helpful to you!

Modern browsers are supposed to load js sequentially, so the js in head is bound to load before the js that webpack packages and inserts.

simple code verification is as follows:

  https://webpack.js.org/config.

Menu