data
data

Reputation: 2813

Globals not accessible from Vue template

For example {{ window }} template gives out a [Vue warn]: Property or method "window" is not defined

Is this intended behaviour? If I understand correctly adding window to the Vue data would be a bad idea.

Upvotes: 1

Views: 41

Answers (1)

Linus Borg
Linus Borg

Reputation: 23968

Yes, this is intended behaviour. The Template is "scoped" to the component instance, and there are only a few exceptions made - {{ Math.random() }} works, for example.

The window object as the global object is not something templates should directly interact with.

If you need to, use a method to get what you need.

Upvotes: 1

Related Questions