nuxt服务端渲染

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

猜你喜欢

转载自www.cnblogs.com/lanshu123/p/10714587.html