Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
Generate random word form one string value in data nuxt js

I need help. In my project (Vue Nuxtjs) I am fetching some random word which generate in my backend Laravel application through api response. I have to Generate random multiple word form one string value in data which I get from my axios route.

this is my data property.

data() {
    return {
        playWord: [],
        results: [],
    }
},

Response enter image description here

And Axios

  async fetch() {
    const {
        data
    } = await this.$axios.get(`words/${this.$route.params.play}/play`);
    this.playWord = data.word

},

I have been trying with Mounted , which give me only one random value.

 mounted() {
    console.log(this.$route.params.play);

    var characters = 'watermelon';
    var result = ""
    var charactersLength = characters.length;

    for (var i = 0; i < 7; i++) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return this.results = result

    console.log(result)

},

And method

    methods: {
    ply() {
        var characters = 'watermelon';
        var result = ""
        var charactersLength = characters.length;

        for (var i = 0; i < i; i++) {
            result += characters.charAt(Math.floor(Math.random() * charactersLength));
        }
        return this.result = ply
    },

},

How can I execute my required

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This will give you 30 variants (or less, depending of the random) of a single baseWord

<template>
  <div>
    <pre>total words: {{ result.length }}</pre>
    <pre>actual list: {{ result }}</pre>
  </div>
</template>

<script>
export default {
  data() {
    return {
      baseWord: 'orange',
      result: [],
    }
  },
  mounted() {
    const randomVariants = [...Array(30)].map(() =>
      this.baseWord
        .split('')
        .sort(() => 0.5 - Math.random())
        .join('')
    )
    const variantsWithoutInitialWord = randomVariants.filter(
      (word) => word !== this.baseWord // removes 'orange' if present
    )
    this.result = [...new Set(variantsWithoutInitialWord)] // removing duplicates
  },
}
</script>

Like this

enter image description here


One thing to keep in mind is to not use a random which is available on both server and client and insert it into the DOM, otherwise you will get a DOM missmatch.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda