- <template>
- <view class="content">
- <image :src="img" ></image>
- <view class="text-area">
- <text class="title">{{title}}</text>
- </view>
- </view>
- </template>
-
- <script>
- export default {
- data() {
- return {
- title: 'Hello',
- img: ''
- }
- },
- onLoad() {
- this.getUrl();
- },
- methods: {
- getUrl: function() {
- let that = this;
- uni.request({
- url: "http://localhost:5167/home/index",
- method: "GET",
- responseType: 'arraybuffer',
- success(res) {
- const arrayBuffer = res.data;
- const blob = new Blob([arrayBuffer], {
- type: 'image/jpeg'
- }); // 创建 Blob 对象
- const imageUrl = URL.createObjectURL(blob); // 通过 Blob 对象创建图片 URL
- that.img = imageUrl; // 将获取到的图片 URL 赋值给 imageUrl
- console.log(that.img)
- }
- })
- }
- }
- }
- </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>