美文网首页前端
nuxt-请求数据

nuxt-请求数据

作者: 清酒08 | 来源:发表于2022-06-24 17:46 被阅读0次

    本文仅仅为笔者笔记,且本文针对拥有vue的基础的人群,若无vue基础请勿喷谢谢。

    请求数据

    demo:

    export default {
      async asyncData({ $axios, params, error }) {
        try {
          const res = await $axios.$get("url")
          return { res }
        } catch (e) {
          error({ statusCode: 404, message: 'Not fount'})
        }
        
      }
    }
    
    
    // 使用的话直接 {{res.xxx}}
    

    通过head设置页面的标题

    export default {
      head() {
        return {
          title: '页面标题'
        }
      }
    }
    

    前端mock工具 json-server

    相关文章

      网友评论

        本文标题:nuxt-请求数据

        本文链接:https://www.haomeiwen.com/subject/qxhbvrtx.html