fetchとは?
ページがレンダリングされる前に、データをstoreに入れるために使用されます。
fetch関数
第一引数にコンテキストを受け取り、コンテキストを使用してstoreに入れます。
コンテキストについては、下記の記事で解説しています。
fetchの利用例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<template> <section> <h1>sample</h1> {{$store.state.msg}}</section> </template> <script> export default{ fetch ({store, params}){ return axios.get('http://xxx').then(() => { store.commit('setMsg', {msg: res.msg}) }); } } </script> |
この記事へのコメントはありません。