Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vue.js Vue i18n:根据服务器返回的密钥转换消息_Vue.js_Vue I18n - Fatal编程技术网

Vue.js Vue i18n:根据服务器返回的密钥转换消息

Vue.js Vue i18n:根据服务器返回的密钥转换消息,vue.js,vue-i18n,Vue.js,Vue I18n,我有一个模板,在事件触发时接收消息密钥。 我将“message.I.want”传递给模板,但i18n没有根据我传递的密钥进行翻译。 我应该如何更新我的代码,以便i18n可以根据我传递的密钥进行翻译 <template> ... <v-card-text>{{ $t("messageKey") }}</v-card-text> ... </template> <script> import Eve

我有一个模板,在事件触发时接收消息密钥。
我将“message.I.want”传递给模板,但i18n没有根据我传递的密钥进行翻译。
我应该如何更新我的代码,以便i18n可以根据我传递的密钥进行翻译

<template>
      ...
      <v-card-text>{{ $t("messageKey") }}</v-card-text>
      ...
</template>

<script>
  import EventBus from "@/eventbus/eventbus.js"

  export default {
    name: "DialogBox",
    data() {
      return {
        messageKey: ""
      }
    },
    methods: {
      popUpDialog(message) {
        console.log("message dialog " + messageKey);
        this.messageKey = messageKey;
      }
    },
    mounted: function () {
      EventBus.$on("showMessageDialog", (messageKey) => {
        this.popUpDialog(messageKey);
      });
    }
  }
</script>


//en.json
{
  "messageKey": "Hello world",  // this was translated on the page
  "message.i.wanted": "message I wanted"
}

...
{{$t(“messageKey”)}
...
从“@/EventBus/EventBus.js”导入EventBus
导出默认值{
名称:“对话框”,
数据(){
返回{
messageKey:“
}
},
方法:{
弹出对话框(消息){
console.log(“消息对话框”+messageKey);
this.messageKey=messageKey;
}
},
挂载:函数(){
EventBus.$on(“showMessageDialog”,(messageKey)=>{
此.popUpDialog(messageKey);
});
}
}
//en.json
{
“messageKey”:“Hello world”,//这是在页面上翻译的
“message.i.wanted”:“message i wanted”
}

ref:

我不知道Vue i18n,但猜测一下,请在不使用quotes@Phil谢谢,你说得对!看起来这只是一个基本的vue语法,所以我甚至在阅读i18n文档时都找不到。。。