【发布时间】:2020-03-12 14:01:34
【问题描述】:
我开始使用 Cloud Google 并在我的代码中实现了翻译 API,但我无法在回调之外使用响应。
methods:{
clicked(){
const text = "Olá";
const target = navigator.language;
googleTranslate.translate(text, target, function(err, translation){
console.log(translation.translatedText)
//this.newText = translation.translatedText;
});
//console.log(this.newText);
},
}
使用或不使用 console.log 显示错误。在this.newText = translation.translatedText;
渲染错误:“TypeError: Cannot read property 'newText' of undefined”
我想在模板中向用户显示答案。我该怎么做?
【问题讨论】:
标签: javascript vue.js google-translation-api