Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loaded scripts are available only with delay #95

Open
fairking opened this issue Jul 16, 2020 · 3 comments
Open

Loaded scripts are available only with delay #95

fairking opened this issue Jul 16, 2020 · 3 comments

Comments

@fairking
Copy link

fairking commented Jul 16, 2020

Only after some certain delay scrips ara available for use in mounted method.
E.g.

head: {
			style: [
				{ type: 'text/css', src: 'stimulsoft/stimulsoft.designer.office2013.whiteblue.css' },
				{ type: 'text/css', src: 'stimulsoft/stimulsoft.viewer.office2013.whiteblue.css' }
			],
			script: [
				{ type: 'text/javascript', src: 'stimulsoft/stimulsoft.reports.js' },
				{ type: 'text/javascript', src: 'stimulsoft/stimulsoft.viewer.js' },
				{ type: 'text/javascript', src: 'stimulsoft/stimulsoft.designer.js' }
			]
		},
mounted() {
    // Version 1 (Not Working, Error: Cannot read property 'Designer' of undefined")
    this.$on('okHead', function () {
        this.stiInit();
    });
    // Or Version 2 (Working)
    this.$on('okHead', function () {
        setTimeout(this.stiInit, 1000);
    });
},
methods: {
    stiInit() {
        var options = new window.Stimulsoft.Designer.StiDesignerOptions(); 
        var designer = new window.Stimulsoft.Designer.StiDesigner(options, "StiDesigner", false);
    }
}

Is there any way to solve that problem without using the delay?

@fairking fairking changed the title Loaded scripts are available with delay Loaded scripts are available only with delay Jul 16, 2020
@ktquez
Copy link
Owner

ktquez commented Jul 16, 2020

Hi @fairking,

The okHead event alerts you that the elements have been created, but does not guarantee that the scripts are loaded, so I think you will need the delay.


Or you can try the onload event, for example:

{ type: 'text/javascript', id: 'stimulsoft-designer', src: 'stimulsoft/stimulsoft.designer.js' }

// ...

this.$on('okHead', function () {
  const sd = document.getElementById('stimulsoft-designer')
  sd.onload = this.stiInit
})

Note: I haven't tested it to see if the code above works, but it can.


Thanks for using.

@fairking
Copy link
Author

Tried, something is not working https://github.com/fairking/stimulsoft-demo

@OvidijusParsiunas
Copy link

OvidijusParsiunas commented Aug 30, 2023

This approach has worked for me, check the live example here:
https://stackblitz.com/edit/vue2-vue-cli-2rdjuu?file=src%2FApp.vue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants