One option is to access the Vue instance through the global reference app
and update the variable container using Vue's reactivity system.
For example:
// define Vue instance
var app = new Vue({
data: {
myVariable: 'initial value'
}
});
// define a JavaScript function that is not a method of Vue.js
function myFunction() {
// access the Vue instance
app.myVariable = 'new value';
}
// call the function to update the variable container
myFunction();
In this example, app
is the global reference to the Vue instance. The myFunction
function accesses app
and updates the myVariable
data property using Vue's reactivity system. The updated value can then be accessed from any methods or templates within the Vue instance.
Asked: 2021-04-13 11:00:00 +0000
Seen: 11 times
Last updated: Jan 25 '22