在我的main.js文件中,我注册了Vue:
import Vue from 'vue';
import VueRouter from 'vue-router';
import VueResource from 'vue-resource';
import VueI18n from 'vue-i18n';
import App from './components/App.vue';
// Register plugins
Vue.use(VueResource);
Vue.use(VueRouter);
Vue.use(VueI18n);
// Create router
const router = new VueRouter({
history: true,
saveScrollPosition: true,
});
router.start({
components: { App },
}, 'body');
现在我想在App.Vue中获取翻译文件:
<script>
export default {
ready() {
/* Set Language */
Vue.locale('nl', function setLanguage() {
return this.$http({
url: '/src/language/nl_NL.js',
method: 'get',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then((response) => {
Vue.locale('nl', response);
Vue.config.lang = 'nl';
}).then(() => {
alert('Error');
});
});
},
};
</script>
我收到错误:'Vue' is not defined
。我做错了什么?
答案 0 :(得分:1)
我的猜测是你错过了App.vue
中vue的import语句,因为vue没有自动将自己注入到vue文件AFAIK中:
<script>
import Vue from 'vue'; // <--
export default {
ready() {
/* Set Language */
Vue.locale('nl', function setLanguage() {
return this.$http({
url: '/src/language/nl_NL.js',
method: 'get',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
})
.then((response) => {
Vue.locale('nl', response);
Vue.config.lang = 'nl';
}).then(() => {
alert('Error');
});
});
},
};
</script>
答案 1 :(得分:0)
根据您的代码我可以理解您的Vue应用程序是在您使Vue使用所有依赖之前创建的。只有在完成所有这些Vue.use(*)后才能创建应用程序实例。它应该这样做。此外,最好在组件内部使用Response.Clear();
Response.ContentType = "application/force-download";
Response.AddHeader("content-disposition", "attachment; filename=publicationCitations.pdf");
// This is the piece you're missing
Response.BinaryWrite(p.generatePublicationCitationReport(pubIDs));
Response.End();
来引用Vue的正确实例。在您的方法中,您可以执行this
,以便保护自己免受范围问题的影响。在子组件内部,您可以使用此。$ root来引用应用程序组件。我希望这会有所帮助。