0
App.vue
とします。 Query.vue
とResult.vue
はその子です。vue.jsのコンポーネント間でデータをやり取りする最善の方法は何ですか?
とルータは、次のようになります
import Query from '@/components/Query'
import Result from '@/components/Result'
export default new Router({
routes: [
{
path: '/',
name: 'query',
component: Query
}, {
path: '/result',
name: 'result',
component: Result
}
]
})
Query.vue
でボタン、クリックされたとき、それがAPIにPOST
リクエストが送信されますがあります:Query.vue
で
this.$http.post(url, {
arg1: arg1,
arg2: arg2
}).then(function (response) {
data = response.data
// I want to do something like:
this.$router.push({path: 'result', payload: data})
}, function (response) {})
そして、私はを処理できます。
しかし、これは不可能なようです。それを作るのにstore
を使うべきですか?
this.$http.post(url, {
data: "some data"
}).then(function (response) {
store.store(response.data)
this.$router.push({path: 'result'})
}, function (response) {})
私はいくつかを渡す必要がありますデータは一方向ですが、 'Result.vue'は' Query.vue'の子ではありません。だから 'vuex'を使う? – HungryMilk
はい。それは最良の方法であり、Vue –
によって推奨されています。どうもありがとう! – HungryMilk