I just started a vue.
I want to send an object array from homeView to SampleView. After searching some information, I used JSON.stringify() and was able to get the data.
The data form I want to send is like below
words: [
{ key: "key", word: "test-name", definition: "test-definition", text: '' },
{ key: "key", word: "test-name", definition: "test-definition", text: '' },
{ key: "key", word: "test-name", definition: "test-ddd", text: '' },
]
<v-btn size="small" :to="{ name: 'WordGame', query: {gameWords: JSON.stringify(words)}}" class="float-right">단어 게임</v-btn>
what I'm curious about is that it is normal way to send an object data by query string?
And what way could I make code better?
HomeView.vue
<template>
<div class="ma-5">
<v-row>
{{ this.date }}
</v-row>
<v-row justify="end">
<v-btn size="small" class="float-right me-1" @click="hideDefinition">{{ hideButton }}</v-btn>
<v-btn size="small" href="/words/new" class="float-right me-1" v-if="isToday">추가하기</v-btn>
<v-btn size="small" :to="{ name: 'WordGame', query: {gameWords: words} }" class="float-right">단어 게임</v-btn>
</v-row>
</div>
</template>
SampleView.vue
<template>
<div class="ma-5">
<v-row
v-for="word in gameWords"
:key="word.key"
>
<v-col>
<v-card
:text="word.word"
>
</v-card>
</v-col>
<v-col>
<v-text-field v-model="word.text">
</v-text-field>
</v-col>
</v-row>
<v-row class="me-1" justify="end">
<v-btn @click="submit">
제출
</v-btn>
</v-row>
</div>
</template>
<script>
export default {
mounted() {
this.init();
},
props: ['gameWords'],
methods: {
init() {
console.log(this.$route.query.gameWords)
},
}
}
</script>
router.js
const router = createRouter({
history: createWebHistory(),
routes: [
{
path: '/word-game',
name: 'WordGame',
component: () => import('../views/SampleView.vue'),
props: true
},
]
});
App.vue
<template>
<v-app>
<v-main>
<v-container>
<voca-header></voca-header>
<router-view></router-view>
</v-container>
</v-main>
</v-app>
</template>