Consider a Vue 3 app where a global property $appName is set to 'MyVueApp'. What will this component render?
import { defineComponent } from 'vue'; export default defineComponent({ template: `<div>{{ $appName }}</div>` });
Global properties are accessible in templates via this context.
Global properties added to the app instance are accessible in components as this.$appName. In templates, you can directly use {{ $appName }} to display the value.
Choose the correct way to add a global method $greet that returns 'Hello' in a Vue 3 app.
Global methods are added to app.config.globalProperties.
In Vue 3, global properties and methods are added to app.config.globalProperties. This makes them accessible in all components via this.$greet().
Given this setup, why does {{ $version }} show nothing in the component?
const app = Vue.createApp({});
app.config.globalProperties.version = '1.0';
app.mount('#app');Component template:{{ $version }}
Check the naming consistency between property definition and usage.
Global properties must be accessed with the same name as defined. Here, the property is defined as version but accessed as $version, so it is undefined in the template.
Given this Vue 3 app code, what will be the displayed count after clicking the button once?
const app = Vue.createApp({
data() { return { count: 0 }; },
methods: {
increment() { this.count++; }
}
});
app.config.globalProperties.$incrementGlobal = function() { this.count += 2; };
app.mount('#app');Component template:
<button @click="$incrementGlobal()">Add 2</button>
<div>Count: {{ count }}</div>Global methods use the component instance as this.
The global method $incrementGlobal is called with this bound to the component instance, so it increments count by 2. Initial count is 0, so after one click it becomes 2.
Choose the correct statement about global properties and methods in Vue 3.
Think about how global properties are accessed and naming conventions.
Global properties are accessible in components via this and by convention start with a $ prefix to avoid conflicts. They are not reactive by default and do not replace Vuex or other state management.