search

Home  >  Q&A  >  body text

Pass $t as prop to a component's internationalized data method

No need to translate in normal way, but I want to translate two object arrays and bind into component

<InfoNews 
           v-for="infonew in infonews"
            :id="infonew.id"
            :title="infonew.title"
            :content="infonew.content"
          />
 data() {
    return {
     infonews: [
        {
          id: "01",
          title: "what we do",
          content:"industke aecimen book. ",
        },
        {
          id: "02",
          title: "our mission",
          content:"ggdddg",
           
        },
      ],
    };

P粉898049562P粉898049562248 days ago376

reply all(1)I'll reply

  • P粉884667022

    P粉8846670222024-03-22 10:23:33

    Make infonews a computed property. Each of the title and content should be translation keys.

    export default {
      computed: {
        infonews() {
          return [
            {
              id: "01",
              title: this.$t("what we do"),
              content: this.$t("industke aecimen book"),
            },
            {
              id: "02",
              title: this.$t("our mission"),
              content: this.$t("ggdddg"),
            },
          ]
        };
      }
    }
    

    reply
    0
  • Cancelreply