3.一次成功的网络请求
<template>
<view class="content">
<image class="logo" src="/static/logo.png"></image>
<view class="text-area">
<text class="title">{{title}}</text>
</view>
<button size="mini" @click="clickBtn">按钮</button>
</view>
</template>
<script>
export default {
data() {
return {
title: 'Hello'
}
},
onLoad() {
},
methods: {
clickBtn(){
uni.request({
url: "https://xxx.fun/xcx.php?text=1",
success: (res) =>{
console.log(res.data);
uni.showToast({
title:res.data.data
});
}
});
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
后端PHP解决跨域问题
<?php
header("Access-Control-Allow-Origin:http://localhost:8080");