我需要全局变量来处理错误。但我不想为每个组件设置输入变量。如何在没有输入变量的情况下观察组件 ABC 中的 $errors?
(without <abc :errors="$errors"></abc>)
Run Code Online (Sandbox Code Playgroud)
索引.js:
Vue.prototype.$errors = {};
new Vue({
el: '#app',
render: h => h(App),
}
Run Code Online (Sandbox Code Playgroud)
应用程序.vue:
...
name: 'App',
components: {
ABC
}
...
methods:{
getContent() {
this.$errors = ...from axis...
}
Run Code Online (Sandbox Code Playgroud)
组件 ABC:
<template>
<div>{{ error }}</div>
</template>
...
watch: {
???
}
Run Code Online (Sandbox Code Playgroud) vue.js ×1