1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| <template> <div class="page"> page is search <ul> <li v-for="(item,idx) in list" :key="idx">{{item}}</li> </ul> </div> </template> <script> import axios from 'axios'; export default { layout: 'search', data() { return { list: [] } }, async asyncData(){ let { status, data: {list}} = await axios.get('http://localhost:3000/city/list') if(status === 200){ return { list } } } } </script> <style scoped> </style>
|
使用asyncData就是服务端渲染,computed只是浏览器的渲染刷新会有闪烁