Today, i we will show you how to use declare global variable in Vue JS. This article will give you simple example of how to use declare global variable in Vue JS. you will learn how to use declare global variable in Vue JS. So let’s follow few step to create example of how to use declare global variable in Vue JS.
Example
<!DOCTYPE html> <html> <head> <title>How to Use declare global variable in Vue JS</title> <script src="https://cdn.jsdelivr.net/npm/vue"></script> </head> <body> <div id="app"> <p>Result : {{myResult}}</p> <button @click="clickFunction()">Click Me</button> </div> <script type="text/javascript"> Vue.mixin({ data: function() { return { myGlobalVar:'this is my Codeplaners.com' } } }) var app = new Vue({ el: '#app', data: { myResult: '' }, methods:{ clickFunction: function () { this.myResult = this.myGlobalVar; } } }) </script> </body> </html>
Output
Result : this is my Codeplaners.com