我正在尝试将语言环境语言变量从 JSON 请求(laravel 生成)加载到 VueJS,因为 VueJS 不支持开箱即用的语言环境。就绪函数警报不会发出警报,但随机文本数据变量会起作用。我知道 VueJS 加载正确。没有控制台错误,webpack 编译了 vue.js 文件。 lang 数组显示为空,lang.email 显示为空白。这是我的问题。任何帮助表示赞赏。
const app = new Vue({
el: '#app',
data: {
lang: [],
randomtext: 'This is Random Text'
},
ready: function() {
alert('THIS DOES NOT ALERT');
this.getLanguage();
},
methods: {
getLanguage: function() {
this.$http.get('/lang/auth').then((response) => {
this.$set("lang", response)
}, (response) => {
alert(response);
});
}
}
});
“lang/auth”
{"email":"Email Address","password":"Password"}
我的html:
<h5 class="content-group">@{{ randomtext }}</h5> // This Works
<input type="text" class="form-control" :placeholder="lang.email"> // This does not
最佳答案
事实上,“准备好”是 deprecated in Vue.js 2
尝试使用“mounted ”代替。
关于javascript - 来自 JSON 的 VueJS 语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41577670/