I am in need of assistance. In my Vue Nuxtjs project, I am fetching random words generated from my backend Laravel application through an API response. I need to generate multiple random words from a single string value in the data obtained from my Axios route.
This is my data property:
data() {
return {
playWord: [],
results: []
};
}
Here is the response and Axios call:
async fetch() {
const { data } = await this.$axios.get(`words/${this.$route.params.play}/play`);
this.playWord = data.word;
}
I have tried using the 'mounted' method, but it only gives me 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));
}
this.results = result;
console.log(result);
}
And here is the method I created:
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));
}
this.result = ply;
},
}
Any suggestions on how to achieve my goal?