question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to access global functions in component markup

See original GitHub issue

I’m not able to access global functions in the markup of a component.

var mySingleton = { myFunction : function() { } }

<my_component v-on:click="mySingleton.myFunction()"></my_component>

mySingleton will be UNDEFINED because of:

(function(scope /**/) { return scope.window.mySingleton.myFunction(); })

If I try to access via

<my_component v-on:click=“window.mySingleton.myFunction()”"></my_component>`

It is still UNDEFINED because of:

(function(scope /**/) { return scope.window.mySingleton.myFunction(); })

Shouldn’t at least case 2 work so that vue does not prepend scope. because I try to access window. ?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

24reactions
JounQincommented, Oct 11, 2017

Vue.prototype.whatever = yourGreatLibrary should work.

https://jsbin.com/pemugaketi

15reactions
ajoriascommented, Mar 2, 2016

Understood. So what is your recommended way to access singletons from component markup without adding them to data (which would make them reactive and this is not wanted). In fact no reactivity here is intended.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Write global functions to use in all components in angular
1. create your global function service, i.e. 'funcs.services.ts' under 'services' directory: import { Injectable } from '@angular/core'; ...
Read more >
How does one access global variables, like $setup, in a ...
Some info is "some global variables are accessible in components" and "none are accessible". So that being the case would a call to...
Read more >
How to Use a Globally Defined Script Inside a React Component
A global variable is defined inside a script tag independent of the React app. This global variable can be data that needs to...
Read more >
Configure the Component Markup and Design Resource for a ...
Mark your resources with access="global" to make it usable outside of your own org, such as to make a component usable by a...
Read more >
How do I use a global function from a custom framework in an ...
I have a custom framework that is loading fine with my Angular app. I can access its global functions via the Console when...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found