我是靠谱客的博主 寂寞鲜花,这篇文章主要介绍Vue——vue3实现前后端交互fetch、axios写法,现在分享给大家,希望可以做个参考。

axios 安装

cnpm install axios --save

App.vue文件

<script>
import axios from 'axios'
export default {
  name: 'App',
  setup () {
    let api = 'https://api.apiopen.top/api/getHaoKanVideo?page=0&size=2'
    // 写法一:fetch
    // fetch(api).then(res => res.json()).then(result => {
    //   store.setList(result,'请求结果')
    // })
    // 写法二:axios
    axios.get(api).then(res => {
      console.log(res, '请求结果 ')
    })
  }
}
</script>

最后

以上就是寂寞鲜花最近收集整理的关于Vue——vue3实现前后端交互fetch、axios写法的全部内容,更多相关Vue——vue3实现前后端交互fetch、axios写法内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部