美文网首页
vue setup axios 使用

vue setup axios 使用

作者: 程序猿的小生活 | 来源:发表于2022-12-12 09:59 被阅读0次

1.使用npm

$ npm install axios

2.main.js 中配置

import axios from 'axios'
const app =   createApp(App)
app.config.globalProperties.$http= axios

3.项目中使用

<template>
    <div @click="get()">网络请求</div>
{{msg}}
</template>

<script setup>
    import{ref} from'vue'
    let msg = ref('');
import {getCurrentInstance} from 'vue'
const currentinstance = getCurrentInstance()
const $http =currentinstance.appContext.config.globalProperties.$http
console.log($http)
let get=()=>{
$http({
  method: 'post',
  url: 'http://103.239.154.90:8088/platform/plogin/getPCode.do',
 params: {//params 拼装在url后面  data拼装在body请求体中
 'mobilephone':'18501548366'
  }
}) .then(function (response) {
      msg.value = response.data.info
      })
      .catch(function (error) {
        console.log(error);
      });;

    
}


</script>

相关文章

网友评论

      本文标题:vue setup axios 使用

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