zoukankan      html  css  js  c++  java
  • NUXT中使用axios,自己项目测试记录

    <template>
      <h4>
        data = {{ res }}
      </h4>
    </template>
    
    <script>
      import axios from 'axios'
      export default {
        name: 'four',
        // 第一种方法
        /*
        async asyncData (context) {
          // const { data } = await axios.get('http://yd.ysedu.com/app/v1/get_home_countdown_details')
          const { data } = await axios({
            method: 'get',
            url: 'http://yd.ysedu.com/app/v1/get_home_countdown_details',
            data: {
              id: 5
            },
            headers: {
              sign: '6ebbd40d0baeef0417bf6b62144f05e3/22307e52eb1895b809031eba30900f80/1578654048/m'
            }
          })
          return { res: data }
        }
        */
    
         // 方法2
        async asyncData (context, callback) {
          axios({
            method: 'get',
            url: 'http://yd.ysedu.com/app/v1/get_home_countdown_details',
            data: {
              id: 5
            },
            headers: {
              sign: 'cf1b832265a99354032d8ced757f1e77/22307e52eb1895b809031eba30900f80/1578654419/m'
            }
          }).then(
            res => {
              callback(null, {res: res.data})
            }
          )
        }
      }
    </script>
    
    <style scoped>
    
    </style>
    

      初学,测试写不好返回结果,经过几次测试终于稳定。

  • 相关阅读:
    053364
    053363
    oracle导出批量表N行记录
    053362
    053361
    053360
    053359
    053358
    053357
    053356
  • 原文地址:https://www.cnblogs.com/ichenchao/p/12177733.html
Copyright © 2011-2022 走看看