<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只是浏览器的渲染刷新会有闪烁