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>
网友评论