I am working on a simple Vue.js application with the following structure:
index.html (only the <body>
for brevity)
<div id="root"></div>
main.js
var settings = {
title: 'My App',
}
new Vue({
el: '#root',
template: '<div>{{ settings.title }}</div>',
})
When I run this code, I encounter the following error:
Property or method "settings" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.
(found in root instance)
I believe the issue arises because Vue expects the variable to be defined in the data store instead of the global scope. Is there a way to declare settings
as a global variable in this context, or perhaps a more effective approach to achieve the desired outcome? I considered passing the config object as a prop to the root Vue
instance, but it seems that only components support props. I welcome any insights or suggestions on how to address this dilemma. Thank you.